Going on the assumption I can use an RSS template as if it were a post loop, how come this returns a php error of “cannot use object of type WP_Query as array in”?
$args = array('tax_query' => array(
'taxonomy' => 'show',
'terms' => 'the-anti-broadcast',)
);
$posts = new WP_Query( $args );
while(have_posts($posts)) : the_post($posts); ?>
The tax_query argument requires nested arrays. Since you did not do that, the code interpreter is picking up the next WP_Query line instead. Please review the examples for tax_query on the WP_Query docs page.
Yes, the RSS template is a specific kind of archive template that generates compatible XML. As long the XML is correct you can modify the template. However, adding a custom query to drive the main loop is sub-optimal. Instead use the “pre_get_posts” action to modify the RSS query. Verify the passed object is the main query and that it’s a feed request before modifying anything.
I don’t see why this is necessary. Why wouldn’t you use the term feed request?
https://example.com/show/the-anti-broadcast/feed/
You’re probably right now that I look at the situation. I just wanted to avoid injecting the extra iTunes (etc) tags and custom field into ALL my feeds through the functions file.
I’ll spend some time learning to use pre_get_posts and will share my results here for anyone who’ll search like I did in the future.
Thanks
This is a proper array to call a post type, taxonomy, and term into a wp_query in an RSS file
$args = array(
'post_type' => 'shows' ,
'orderby' => 'date' ,
'order' => 'DESC' ,
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => 'show',
'field' => 'tag_ID',
'terms' => '3'
)
)
);
$q = new WP_Query($args);
while($q->have_posts()) : $q->the_post(); ?>