The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Does get_posts() support tax_query? (4 posts)

  1. helgatheviking
    Posted 5 years ago #

    The codex says that get_posts uses all the same arguments as query_posts, so why doesn't the tax_query work with get_posts?

    $myquery['tax_query'] = array(
    		'taxonomy' => 'portfolio-tags',
    		'terms' => array('bacon'),
    		'field' => 'slug',
    $myposts = get_posts( $myquery );
    if ($myposts) :
      echo "bacon here!"
      echo "no freaking bacon";

    echos out "no freaking bacon" which is obviously not the end result i want, but was a quick way to test whether it was pulling any data.

    but if i change $myposts to

    $myposts = query_posts( $myquery );

    then i get a result.

  2. Azuaron
    Posted 5 years ago #

    I got mine to work:

    $args = array(	'numberposts'=>-1,
    $series_posts = get_posts($args);

    The only difference I can see is that my "terms" isn't in an array. That really shouldn't make a difference, though, since it's definitely supposed to work with arrays.

  3. helgatheviking
    Posted 5 years ago #

    thanks! actually the difference is that you've defined the post type and the taxonomy i was trying to pull from only applied to a specific post type. apparently get_posts() only searches posts by default unless you define another post type.

  4. Azuaron
    Posted 5 years ago #

    Ah, I didn't realize you were (also) working with an alternate post type.

Topic Closed

This topic has been closed to new replies.

About this Topic