search post by post title in wordpres
Code
$args = array("post_type" => "mytype", "s" => $title);
$query = get_posts( $args );
search post by post title in wordpres
Code
$args = array("post_type" => "mytype", "s" => $title);
$query = get_posts( $args );
wp search post type results page
01
02
03
04
05
06
07
08
09
10
11
12
/**
* This function modifies the main WordPress query to include an array of
* post types instead of the default 'post' post type.
*
* @param object $query The main WordPress query.
*/
function tg_include_custom_post_types_in_search_results( $query ) {
if ( $query->is_main_query() && $query->is_search() && ! is_admin() ) {
$query->set( 'post_type', array( 'post', 'movies', 'products', 'portfolio' ) );
}
}
add_action( 'pre_get_posts', 'tg_include_custom_post_types_in_search_results' );
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us