• Resolved bbtodd

    (@bbtodd)


    I’m a bit baffled why a custom post type causes an error when I query for it, unless I also include taxonomy terms.

    This causes a 500 internal error.
    <?php $loop = new WP_Query( array( 'post_type' => 'venue', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC' ) ); ?>

    However, I can get ‘venue’ to loop but only if I include a taxonomy query.

    <?php $loop = new WP_Query( array( 'post_type' => 'venue', 'posts_per_page' => -1, 'orderby' => 'title', 'order' => 'ASC', 'tax_query' => array(
            array (
                'taxonomy' => 'venue-affiliations',
                'field' => 'slug',
                'terms' => 'ADAA',
            )
        ), ) ); ?>

    So if I include a taxonomy query the loop works. If the taxonomy isn’t there then the page load crashes once it gets to the loop. But not all venues have an affiliation, so I can’t get those to display.

    I have another custom post type ‘artists’ and the above code works perfectly when I loop that.

    So I thought maybe it had to do with the way the custom post type was registered in functions.php but both ‘artists’ and ‘venue’ setup are nearly identical.

    Any clues why this might be happening?

    • This topic was modified 4 years, 2 months ago by bbtodd.
    • This topic was modified 4 years, 2 months ago by bbtodd.
Viewing 1 replies (of 1 total)
  • Thread Starter bbtodd

    (@bbtodd)

    Resolved. There were several posts with some kind of issue crashing the site. Instead of trying to load all posts I went through the tedious process of changing the number of posts_per_page until the site crashed, then tracked down which post that was and changing that to draft mode. Now the loop works.

Viewing 1 replies (of 1 total)
  • The topic ‘One particular post type causes a query error unless I also include taxonomy’ is closed to new replies.