$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>wp query - Live search by custom tag|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

wp query - Live search by custom tag

matteradmin8PV0评论

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?

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?

Share Improve this question edited Mar 14, 2019 at 20:23 rudtek 6,4035 gold badges30 silver badges52 bronze badges asked Mar 14, 2019 at 20:12 CrispyCrispy 11 bronze badge 1
  • When you tried to set 'taxonomy'=>'custom_tags', did you add it just like that to the WP_Query arguments array? Or did you try it like 'tax_query' => array( array( 'taxonomy' => 'custom_tags' ) )? – Antti Koskinen Commented Mar 14, 2019 at 21:44
Add a comment  | 

1 Answer 1

Reset to default 0

'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' 

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far