Live search by custom tag

by Crispy   Last Updated March 14, 2019 21:08 PM

Live search:

$the_query = new WP_Query( array( 's' => esc_attr( $_POST['keyword'] ), 'post_type' => 'custom_type', 'sentence' => 'true' ));
if( $the_query->have_posts() ) :
    while( $the_query->have_posts() ): $the_query->the_post(); ?>

        <a href="<?php echo esc_url( post_permalink() ); ?>"><?php the_title();?></a>

    <?php endwhile;

I created a custom post type "custom_type" and 2 taxonomies "custom_cat" (hierarchical = true) for categories and "custom_tags" (hierarchical = false) for tags.

I need to create a live search by custom tags.

I tried to set 'taxonomy'=>'custom_tags' but this parameter was ignored and search returned all "custom_type" posts by keyword. Does anyone know solution?



Answers 1


'post_type' => 'custom_type' is a reference to your post type.

You need to change custom_type to the actual post type that you created / registered.

So, if your post type was my_cool_dregs then the line would be:

'post_type' => 'my_cool_dregs'

The same holds true with 'taxonomy'=>'custom_tags'

You need use the actual taxonomy name that you registered. If your taxonomy was my_dreg_types then that line would be:

'taxonomy'=>'my_dreg_types' 
rudtek
rudtek
March 14, 2019 20:26 PM

Related Questions


Custom search for a custom post type in WordPress

Updated September 26, 2018 12:08 PM



Ideas on how to organize a project

Updated August 19, 2016 08:03 AM