WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] query_posts & custom taxonomies (4 posts)

  1. NWTD
    Member
    Posted 1 year ago #

    I created a custom post type and custom taxonomy for it. I'm trying to query posts from the post type and by the custom taxonomy.

    For instance, I'dlike to query posts from the "Directors" category in this custom taxonomy. Looking at the url for this taxonmy, I see it has a tag_ID of 22.

    ...edit-tags.php?action=edit&taxonomy=positions&tag_ID=22&post_type=biography

    I'm using the following code to query:

    <?php query_posts('post_type=biography&tag_ID=22'); if ( have_posts() ) : ?>

    However, my results are not what I'm looking for. Any help would be appreciated.

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    Try it with:

    <?php
    $args = array(
      'post_type' => 'biography',
    	'tax_query' => array(
    		array(
    			'taxonomy' => 'positions',
    			'field' => 'id',
    			'terms' => array(22)
    		)
    	)
    );
    query_posts($args); if ( have_posts() ) : ?>

    http://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters

  3. NWTD
    Member
    Posted 1 year ago #

    Thank you! I'm still a php novice so I'm piecing this as I go.

  4. MJMarcell
    Member
    Posted 1 year ago #

    Try:

    <?php query_posts('category_name=Directors'); ?>

    <?php while (have_posts()) : the_post(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.