• Resolved unsavouryindividual

    (@unsavouryindividual)


    Season greetings,
    I’ve followed these instructions to create a custom RSS feed and plan on working my way from there. I’m learning WP RSS from scratch.

    I need to call posts that have a term in my custom taxonomy. I couldn’t find anything online as WP generates its own feeds for every term. My situation is different as I’m building a feed to submit to podcast directories and I need to include the mp3 URLs which are handled by a custom field, as well as including the other tags iTunes etc requires in a feed.

    Can I simply treat my RSS template file as if it’s a loop in a custom archive file?

    Many thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter unsavouryindividual

    (@unsavouryindividual)

    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); ?>
    Moderator bcworkz

    (@bcworkz)

    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/

    Thread Starter unsavouryindividual

    (@unsavouryindividual)

    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

    Thread Starter unsavouryindividual

    (@unsavouryindividual)

    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(); ?>
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Custom RSS for taxonomy term’ is closed to new replies.