• Hi! I’m trying to get all posts in the post type ‘color’, that are tagged with a certain tag in the custom taxonomy, ‘colorname’.

    I’ve tried the following queries, and neither work as expected:

    $args = array( ‘post_type’ => ‘color’,
    ‘posts_per_page’ => -1,
    ‘tax_query’ => array( array (
    ‘taxonomy’ => ‘colorname’,
    ‘field’ => ‘slug’,
    ‘terms’ => $slug
    ) )
    );
    $myposts = query_posts( $args );

    $args = array(‘colorname’ => $page_title,
    ‘post_type’ => ‘color’,
    ‘post_status’ => ‘publish’,
    ‘posts_per_page’ => -1,
    ‘caller_get_posts’=> 1
    );
    $myposts = query_posts( $args );

    What am I missing? Thank you ??

Viewing 1 replies (of 1 total)
  • You did not show the code used to process the query (should be a couple of lines like ‘while ($myposts->have_posts() etc’).

    If that is the case, the problem is that query_posts() returns an array of post objects, not a WP_Query object that is needed by have_posts() and other functions.

    Try changing this:

    $myposts = query_posts( $args );

    to this:

    $myposts = new WP_Query( $args );

    If this does not work, post 10 or so lines following the query. And, please enclose the code in backticks so that it will be formatted properly.

Viewing 1 replies (of 1 total)
  • The topic ‘Query for getting posts in a custom post type, custom taxonomy?’ is closed to new replies.