• Guys,
    am playing with custom post types and custom taxonomies . i have registered the custom post type. and custom taxonomies also added. i want to query the custom post using the categories name i have added. when am using the following query it displays all the posts.

    <?php query_posts('post_type=>sample_content&category_name=>bannertop');?>.
    i need help on how to query the particular custom posts using custom category . and i want to know any other methods are available to query particular posts(custom)?……….

    Thanks in advance
    Guru4ever

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    What is the name of the custom taxonomy you registered?

    Try it with a “tax_query”: https://codex.www.ads-software.com/Function_Reference/WP_Query#Taxonomy_Parameters

    example [untested]:

    <?php
    $args = array(
      'post_type'   => 'sample_content',
      'tax_query' => array(
    		array(
    			'taxonomy' => 'taxonomy_name',
    			'field' => 'slug',
    			'terms' => 'bannertop'
    		)
    	)
    );
    query_posts($args);
    ?>

    Change “taxonomy_name” to the taxonomy name you registered.

    Also read how to pass parameters to functions: https://codex.www.ads-software.com/How_to_Pass_Tag_Parameters#Tags_with_query-string-style_parameters

    Thread Starter guru4ever

    (@guru4ever)

    Hi keesiemeijer,
    thanks for the reply , i have tried what you suggest it works.but it displays all the posts in that category.i want to display particular posts under the category bannertop. post slug name is “calendar”. help needed.

    <?php
    $args = array(
      'post_type'   => 'sample_content',
      'tax_query' => array(
    		array(
    			'taxonomy' => 'site-categories',
    			'field' => 'slug',
    			'terms' => 'bannertop'
    		)
    	)
    );
    query_posts($args);
    ?>
    <?php?>
    <?php while ( have_posts() ) : the_post(); ?>
    <h3><?php the_title()?></h3>
    <?php the_content()?>
    <?php endwhile; wp_reset_query(); ?>

    Thanks in advance—
    Guru4ever

    Moderator keesiemeijer

    (@keesiemeijer)

    If you want to query a specific post you can just use:

    <?php query_posts('post_type=sample_content&name=calendar'); ?>

    or

    <?php
    $args = array(
      'post_type'   => 'sample_content',
      'name' => 'calendar',
      'tax_query' => array(
    		array(
    			'taxonomy' => 'site-categories',
    			'field' => 'slug',
    			'terms' => 'bannertop'
    		)
    	)
    );
    query_posts($args);
    ?>

    https://codex.www.ads-software.com/Function_Reference/WP_Query#Post_.26_Page_Parameters

    Thread Starter guru4ever

    (@guru4ever)

    hi keesiemeijer,

    Thanks. now i got it.. am having one more question. am using custom post type . in that am given capability-type as page . what is the best practice whether to use post or page in custom post-type capability.need help

    Regards,
    Guru4ever

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Querying custom taxonomies in the custom post type using query posts’ is closed to new replies.