Support » How-To and Troubleshooting » [Resolved] tax_query not getting what I expect

[Resolved] tax_query not getting what I expect

  • I have a custom content type called media_player. I have a taxonomy for it called sermon_series.

    Most of my singles have terms that are children of the term ‘sermons’

    I’m trying to get the three most recent media_player items in that have or are children of the ‘sermons’ term.

    The query I have is not getting the latest one, but rather 2-4. 2-4 have the same term, item 1 has a new one.

    I narrowed it down some, using the newsest one specifically, so here’s my current query:

    $args = array(
                            'post_type' => 'media_player'
                            ,'post_status' => 'publish'
                            ,'posts_per_page' => 3
                            ,'no_found_rows' => 1
                            ,'orderby' => 'date'
                            ,'order' => 'desc'
                            ,'tax_query' => array(
                                    'taxonomy' => 'sermon_series',
                                    'field' => 'name',
                                    'terms' => array('the-resiliant-life'),

    This gets me NO results, even though the 1 latest item has the term ‘the-resiliant-life’.

    I’ve verified that that one is published, not private, etc.

    The SQL that gets sent with that query is
    SELECT wpada_posts.ID FROM wpada_posts WHERE 1=1 AND 0 = 1 AND wpada_posts.post_type = 'media_player' AND ((wpada_posts.post_status = 'publish' OR wpada_posts.post_status = 'private')) GROUP BY wpada_posts.ID ORDER BY wpada_posts.post_date desc LIMIT 0, 3

    Which you’ll note doesn’t have any term ids in it at all. Where am I going wrong?

Viewing 5 replies - 1 through 5 (of 5 total)
  • What is ‘no_found_rows’? I’ve never heard of that parameter before.

    You also have the tax_query -> field value set to “name”, which is not a valid option. You need to use ID or slug.

    And “resiliant” is incorrect spelling. It should be “resilient”. (Of course, if it’s spelled wrong in your system it should work fine as-is…but just in case, check your spelling and make sure it matches)

    You can read about no_found_rows here: http://flavio.tordini.org/speed-up-wordpress-get_posts-and-query_posts-functions

    The spelling error was a good clue as to why it was different for me from dev to live, I had it wrong on dev. My core problem still exists though, the query I *really* want is:

    ,'tax_query' => array(
                                    'taxonomy' => 'sermon_series',
                                    'field' => 'slug',
                                    'terms' => array('sermons'),

    Because the-resilient-life is a child of sermons, but it doesn’t show up.

    I’m confused. What is “sermon-series”? You say you have:

    A custom post type called “media_player”

    A custom taxonomy term called “sermon_series”

    A custom taxonomy term called “sermons”

    And you want to pull the most recent 3 posts from the “sermons” taxonomy.

    What type of taxonomy is it? Hierarchical (categories) or not (tags)? Is “sermons” a child of “sermon_series”, or is “sermon_series” the slug of “sermons”? Or are they two different things?

    And is there a reason you have a double array in the query? (I seem to recall a need for that, but I don’t remember why, or if I’m imagining it)

    The post type is media_player. The texonomy is hierarchical and is called sermon_series. The term is sermons, and I want all the children of sermons.

    The double array is there because that’s how they had it in the codex and I’m trusting them. 🙂

    I figured this out. There’s a taxonomy cache stored in the options table. It isn’t being flushed when I make a new term, so my new one isn’t available as a child.

    I simply removed that row from the table and it was recreated for me with all the proper elements.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[Resolved] tax_query not getting what I expect’ is closed to new replies.
Skip to toolbar