Getting multiple custom post_types in one url

I’m getting a json feed from the JSON feed plugin through index.php/feed/json?post_type=posttype1. I would like to get multiple post_types in one url(e.g. index.php/feed/json?post_type=posttype1,posttype2). I’ve tried the following piece of code in my theme’s functions.php:

function myFeedFilter($query) 
    // Check if we are requesting a feed. 
    if ($query->is_feed)
            // If a Feed do we have the post_type URL parameter (query_string)?
            if (isset($_GET['post_type']))
                    // Convert the post_type URL parameter to an array. Then set the query post_type value to that array
                    $post_types = explode(',', $_GET['post_type']);
                    $query->post_type = $post_types;
    return $query;

But this does not seem to work. It does nothing. I’m running wordpress 4.7.4

Read more here: Getting multiple custom post_types in one url

Leave a Reply

Your email address will not be published. Required fields are marked *