Skip to main content
replaced http://wordpress.stackexchange.com/ with https://wordpress.stackexchange.com/
Source Link

If you want to limit the filter from this answerthis answer (add that function to your plugin or your theme’s functions.php) just to one query, remove the filter when you are done:

add_filter( 'posts_search', '__search_by_title_only', 500, 2 );

$query = new WP_Query(
    array(
        's'         => 'mykeyword myotherkeyword',
        'cat'       => array( 22, 32 ),
        'orders'    => 'DESC',
        'showposts' => 6
    )
);

remove_filter( 'posts_search', '__search_by_title_only', 500 );

if ( $query->have_posts() ) :
    while ( $query->have_posts() ) :
        $query->the_post();
        the_title( '<p>', '</p>' );
    endwhile;

    wp_reset_postdata();
endif;

If you want to limit the filter from this answer (add that function to your plugin or your theme’s functions.php) just to one query, remove the filter when you are done:

add_filter( 'posts_search', '__search_by_title_only', 500, 2 );

$query = new WP_Query(
    array(
        's'         => 'mykeyword myotherkeyword',
        'cat'       => array( 22, 32 ),
        'orders'    => 'DESC',
        'showposts' => 6
    )
);

remove_filter( 'posts_search', '__search_by_title_only', 500 );

if ( $query->have_posts() ) :
    while ( $query->have_posts() ) :
        $query->the_post();
        the_title( '<p>', '</p>' );
    endwhile;

    wp_reset_postdata();
endif;

If you want to limit the filter from this answer (add that function to your plugin or your theme’s functions.php) just to one query, remove the filter when you are done:

add_filter( 'posts_search', '__search_by_title_only', 500, 2 );

$query = new WP_Query(
    array(
        's'         => 'mykeyword myotherkeyword',
        'cat'       => array( 22, 32 ),
        'orders'    => 'DESC',
        'showposts' => 6
    )
);

remove_filter( 'posts_search', '__search_by_title_only', 500 );

if ( $query->have_posts() ) :
    while ( $query->have_posts() ) :
        $query->the_post();
        the_title( '<p>', '</p>' );
    endwhile;

    wp_reset_postdata();
endif;
added 123 characters in body
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

If you want to limit the filter from this answer (add that function to your plugin or your theme’s functions.php) just to one query, remove the filter when you are done:

add_filter( 'posts_search', '__search_by_title_only', 500, 2 );

$query = new WP_Query( 
 's=mykeyword&cat=22   array(
        's'         => 'mykeyword myotherkeyword',32&order=dsc&showposts=6'
        'cat'       => array( 22, 32 ),
        'orders'    => 'DESC',
        'showposts' => 6
    )
);

remove_filter( 'posts_search', '__search_by_title_only', 500 );

if ( $query->have_posts() ) :
    while ( $query->have_posts() ) :
        $query->the_post();
        the_title( '<p>', '</p>' );
    endwhile;

    wp_reset_postdata();
endif;

If you want to limit the filter from this answer just to one query, remove the filter when you are done:

add_filter( 'posts_search', '__search_by_title_only', 500, 2 );

$query = new WP_Query( 's=mykeyword&cat=22,32&order=dsc&showposts=6' );

remove_filter( 'posts_search', '__search_by_title_only', 500 );

if ( $query->have_posts() ) :
    while ( $query->have_posts() ) :
        $query->the_post();
        the_title( '<p>', '</p>' );
    endwhile;

    wp_reset_postdata();
endif;

If you want to limit the filter from this answer (add that function to your plugin or your theme’s functions.php) just to one query, remove the filter when you are done:

add_filter( 'posts_search', '__search_by_title_only', 500, 2 );

$query = new WP_Query( 
    array(
        's'         => 'mykeyword myotherkeyword',
        'cat'       => array( 22, 32 ),
        'orders'    => 'DESC',
        'showposts' => 6
    )
);

remove_filter( 'posts_search', '__search_by_title_only', 500 );

if ( $query->have_posts() ) :
    while ( $query->have_posts() ) :
        $query->the_post();
        the_title( '<p>', '</p>' );
    endwhile;

    wp_reset_postdata();
endif;
added 138 characters in body
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459

If you want to limit the filter from this answer just to one query, remove the filter when you are done:

add_filter( 'posts_search', '__search_by_title_only', 500, 2 );

$query = new WP_Query( 's=mykeyword&cat=22,32&order=dsc&showposts=6' );

remove_filter( 'posts_search', '__search_by_title_only', 500 ); 

if ( $query->have_posts() ) :
    while ( $query->have_posts() ) :
        $query->the_post();
        the_title( '<p>', '</p>' );
    endwhile;

    wp_reset_postdata();
endif;

If you want to limit the filter from this answer just to one query, remove the filter when you are done:

add_filter( 'posts_search', '__search_by_title_only', 500, 2 );

$query = new WP_Query( 's=mykeyword&cat=22,32&order=dsc&showposts=6' );

remove_filter( 'posts_search', '__search_by_title_only', 500 );

If you want to limit the filter from this answer just to one query, remove the filter when you are done:

add_filter( 'posts_search', '__search_by_title_only', 500, 2 );

$query = new WP_Query( 's=mykeyword&cat=22,32&order=dsc&showposts=6' );

remove_filter( 'posts_search', '__search_by_title_only', 500 ); 

if ( $query->have_posts() ) :
    while ( $query->have_posts() ) :
        $query->the_post();
        the_title( '<p>', '</p>' );
    endwhile;

    wp_reset_postdata();
endif;
Source Link
fuxia
  • 107.1k
  • 38
  • 255
  • 459
Loading