WordPress.org

Support

[Resolved] RSS Feed parameters

Viewing 15 replies - 1 through 15 (of 26 total)
  • Plugin Author Rachel Carden

    @bamadesigner

    You basically need to hook into the query for the RSS feed so you can add a tax query.

    Add the following action to your code, probably your functions.php:

    NOTE: if you print out the query, and you’re not in a development environment, then you’ll want to wrap the code in some logic so only you can see what’s happening.

    Also, the feed pages are severely cached so you might have to refresh A LOT between code changes OR empty your cache every time.

    add_action( 'pre_get_posts', 'my_website_pre_get_posts' );
    function my_website_pre_get_posts( &$query ) {
    
       // There's a 'feed' query variable that lets you
       // know you're running a feed so you can only run
       // your code during a feed.
       if ( $feed = get_query_var( 'feed' ) ) {
    
          // uncomment to print the query so you
          // can see what parameters are set
          /*echo "<pre>";
          print_r( $query );
          echo "</pre>";*/
    
          // You should also have a query variable for
          // 'schools' set to whatever the school name is
          if ( $school = get_query_var( 'schools' ) ) {
    
             // define tax query
             $query->tax_query->queries[] = array(
                'taxonomy' => 'schools',
                'terms' => array( $school ),
                'include_children' => 1,
                'field' => 'slug',
                'operator' => 'IN'
                );
    
          }
    
       }
    
    }
    Jeff

    @jhanbycarrolltongroupcom

    That makes sense. I’m just not sure where I’m pulling the school slug from. The ‘schools’ query variable isn’t showing up in the global query object.

    Do I need to modify the URL or do I need to add rewrite rules to make the query recognize the school from the URL?

    Plugin Author Rachel Carden

    @bamadesigner

    How do you have this feed URL work? Did you add_rewrite_rule()?

    Jeff

    @jhanbycarrolltongroupcom

    I did not. I just added “feed” at the end of the URL to get the post-specific feed.

    Plugin Author Rachel Carden

    @bamadesigner

    Can you show me what the $query looks like?

    Jeff

    @jhanbycarrolltongroupcom

    Something else must be going on, because it appears the query thinks its on the products page (we are running the WP e-Commerce plugin).

    URL: http://lensnola.staging.wpengine.com/school/lycee-francais/feed/

    Response:

    WP_Query Object
    (
        [query_vars] => Array
            (
                [post_status] => publish
                [post_parent] => 0
                [order] => ASC
                [post_type] => wpsc-product
                [pagename] => products-page
                [orderby] => ID
                [error] =>
                [m] => 0
                [p] => 0
                [subpost] =>
                [subpost_id] =>
                [attachment] =>
                [attachment_id] => 0
                [name] =>
                [static] =>
                [page_id] => 0
                [second] =>
                [minute] =>
                [hour] =>
                [day] => 0
                [monthnum] => 0
                [year] => 0
                [w] => 0
                [category_name] =>
                [tag] =>
                [cat] =>
                [tag_id] =>
                [author_name] =>
                [feed] =>
                [tb] =>
                [paged] => 0
                [comments_popup] =>
                [meta_key] =>
                [meta_value] =>
                [preview] =>
                [s] =>
                [sentence] =>
                [fields] =>
                [menu_order] =>
                [category__in] => Array
                    (
                    )
    
                [category__not_in] => Array
                    (
                    )
    
                [category__and] => Array
                    (
                    )
    
                [post__in] => Array
                    (
                    )
    
                [post__not_in] => Array
                    (
                    )
    
                [tag__in] => Array
                    (
                    )
    
                [tag__not_in] => Array
                    (
                    )
    
                [tag__and] => Array
                    (
                    )
    
                [tag_slug__in] => Array
                    (
                    )
    
                [tag_slug__and] => Array
                    (
                    )
    
            )
    
        [tax_query] =>
        [meta_query] =>
        [post_count] => 0
        [current_post] => -1
        [in_the_loop] =>
        [comment_count] => 0
        [current_comment] => -1
        [found_posts] => 0
        [max_num_pages] => 0
        [max_num_comment_pages] => 0
        [is_single] =>
        [is_preview] =>
        [is_page] => 1
        [is_archive] =>
        [is_date] =>
        [is_year] =>
        [is_month] =>
        [is_day] =>
        [is_time] =>
        [is_author] =>
        [is_category] =>
        [is_tag] =>
        [is_tax] =>
        [is_search] =>
        [is_feed] =>
        [is_comment_feed] =>
        [is_trackback] =>
        [is_home] =>
        [is_404] =>
        [is_comments_popup] =>
        [is_paged] =>
        [is_admin] =>
        [is_attachment] =>
        [is_singular] => 1
        [is_robots] =>
        [is_posts_page] =>
        [is_post_type_archive] =>
        [query_vars_hash] => 6c0c4c8bcede69bf39f0c714b5b6a57c
        [query_vars_changed] =>
        [thumbnails_cached] =>
        [query] => Array
            (
                [post_status] => publish
                [post_parent] => 0
                [order] => ASC
                [post_type] => wpsc-product
                [pagename] => products-page
                [orderby] => ID
            )
    
        [queried_object] => WP_Post Object
            (
                [ID] => 38080
                [post_author] => 1
                [post_date] => 2013-03-21 14:47:58
                [post_date_gmt] => 2013-03-21 19:47:58
                [post_content] => [productspage]
                [post_title] => Products Page
                [post_excerpt] =>
                [post_status] => publish
                [comment_status] => closed
                [ping_status] => closed
                [post_password] =>
                [post_name] => products-page
                [to_ping] =>
                [pinged] =>
                [post_modified] => 2013-04-03 10:08:58
                [post_modified_gmt] => 2013-04-03 15:08:58
                [post_content_filtered] =>
                [post_parent] => 0
                [guid] => http://lensnola.staging.wpengine.com/products-page/
                [menu_order] => 0
                [post_type] => page
                [post_mime_type] =>
                [comment_count] => 0
                [filter] => raw
            )
    
        [queried_object_id] => 38080
        [is_product] => 1
    )

    Plugin Author Rachel Carden

    @bamadesigner

    You may have to do add_rewrite_rule() so you can define the parameters.

    Would probably be something like:

    add_action( 'wp_loaded', 'my_website_rewrite_rules' );
    function my_website_rewrite_rules() {
       add_rewrite_rule( '^school/([^\/]+)/feed/?$','index.php?feed=feed&schools=$matches[1]', 'top' );
    }
    Plugin Author Rachel Carden

    @bamadesigner

    You may have to do add_rewrite_rule() so you can define the parameters.

    Would probably be something like:

    add_action( 'wp_loaded', 'my_website_rewrite_rules' );
    function my_website_rewrite_rules() {
       add_rewrite_rule( '^school/([^\/]+)/feed/?$','index.php?feed=feed&schools=$matches[1]', 'top' );
    }
    Jeff

    @jhanbycarrolltongroupcom

    Not sure why WP e-Commerce is messing with the query, but I deactivated it and it appears everything is working as expected except the actual feed. If I remove my die statement and let the request complete, it redirects back to the school page (lensnola.staging.wpengine.com/school/lycee-francais/).

    Query after my pre_get_posts hook with rewrite rules enabled:

    WP_Query Object
    (
        [query_vars] => Array
            (
                [feed] => feed
                [school] => lycee-francais
                [post_type] => school
                [name] => lycee-francais
                [error] =>
                [m] => 0
                [p] => 0
                [post_parent] =>
                [subpost] =>
                [subpost_id] =>
                [attachment] =>
                [attachment_id] => 0
                [static] =>
                [pagename] =>
                [page_id] => 0
                [second] =>
                [minute] =>
                [hour] =>
                [day] => 0
                [monthnum] => 0
                [year] => 0
                [w] => 0
                [category_name] =>
                [tag] =>
                [cat] =>
                [tag_id] =>
                [author_name] =>
                [tb] =>
                [paged] => 0
                [comments_popup] =>
                [meta_key] =>
                [meta_value] =>
                [preview] =>
                [s] =>
                [sentence] =>
                [fields] =>
                [menu_order] =>
                [category__in] => Array
                    (
                    )
    
                [category__not_in] => Array
                    (
                    )
    
                [category__and] => Array
                    (
                    )
    
                [post__in] => Array
                    (
                    )
    
                [post__not_in] => Array
                    (
                    )
    
                [tag__in] => Array
                    (
                    )
    
                [tag__not_in] => Array
                    (
                    )
    
                [tag__and] => Array
                    (
                    )
    
                [tag_slug__in] => Array
                    (
                    )
    
                [tag_slug__and] => Array
                    (
                    )
    
            )
    
        [tax_query] => stdClass Object
            (
                [queries] => Array
                    (
                        [0] => Array
                            (
                                [taxonomy] => school
                                [terms] => Array
                                    (
                                        [0] => lycee-francais
                                    )
    
                                [include_children] => 1
                                [field] => slug
                                [operator] => IN
                            )
    
                    )
    
            )
    
        [meta_query] =>
        [post_count] => 0
        [current_post] => -1
        [in_the_loop] =>
        [comment_count] => 0
        [current_comment] => -1
        [found_posts] => 0
        [max_num_pages] => 0
        [max_num_comment_pages] => 0
        [is_single] => 1
        [is_preview] =>
        [is_page] =>
        [is_archive] =>
        [is_date] =>
        [is_year] =>
        [is_month] =>
        [is_day] =>
        [is_time] =>
        [is_author] =>
        [is_category] =>
        [is_tag] =>
        [is_tax] =>
        [is_search] =>
        [is_feed] => 1
        [is_comment_feed] => 1
        [is_trackback] =>
        [is_home] =>
        [is_404] =>
        [is_comments_popup] =>
        [is_paged] =>
        [is_admin] =>
        [is_attachment] =>
        [is_singular] => 1
        [is_robots] =>
        [is_posts_page] =>
        [is_post_type_archive] =>
        [query_vars_hash] => 7832e8aa476657087351138dffd158ec
        [query_vars_changed] =>
        [thumbnails_cached] =>
        [query] => Array
            (
                [feed] => feed
                [school] => lycee-francais
                [post_type] => school
                [name] => lycee-francais
            )
    
    )
    Plugin Author Rachel Carden

    @bamadesigner

    I forgot about the archive thing for CPT-onomies. Try this:

    and, FYI, you shouldn’t need the ‘pre_get_posts’ action if you’re doing the rewrite rule.

    add_action( 'wp_loaded', 'my_website_rewrite_rules' );
    function my_website_rewrite_rules() {
       add_rewrite_rule( '^school/([^\/]+)/feed/?$','index.php?feed=feed&schools=$matches[1]&cpt_onomy_archive=1', 'top' );
    }
    Jeff

    @jhanbycarrolltongroupcom

    That doesn’t seem to work. I commented out the pre_get_posts hook and the feed is still empty.

    In functions.php (note I uncommented the pre_get_posts to show where I’m printing the query; results below)

    add_action( 'pre_get_posts', 'largo_child_pre_get_posts' );
    function largo_child_pre_get_posts( &$query ) {
    
       if ( $feed = get_query_var( 'feed' ) ) {
    
    	  // uncomment to print the query so you
          // can see what parameters are set
        print_r( $query );
    	  die('testing');
    
          // You should also have a query variable for
          // 'schools' set to whatever the school name is
          if ( $school = get_query_var( 'school' ) ) {
    
          	// define tax query
             $query->tax_query->queries[] = array(
                'taxonomy' => 'school',
                'terms' => array( $school ),
                'include_children' => 1,
                'field' => 'slug',
                'operator' => 'IN'
                );
          }
       }
    }
    
    add_action( 'wp_loaded', 'largo_child_rewrite_rules' );
    function largo_child_rewrite_rules() {
       add_rewrite_rule( '^school/([^\/]+)/feed/?$','index.php?feed=feed&schools=$matches[1]&cpt_onomy_archive=1', 'top' );
    }

    Results of print_r (before adding the tax_queries):

    WP_Query Object
    (
        [query_vars] => Array
            (
                [feed] => feed
                [school] => lycee-francais
                [post_type] => school
                [name] => lycee-francais
                [error] =>
                [m] => 0
                [p] => 0
                [post_parent] =>
                [subpost] =>
                [subpost_id] =>
                [attachment] =>
                [attachment_id] => 0
                [static] =>
                [pagename] =>
                [page_id] => 0
                [second] =>
                [minute] =>
                [hour] =>
                [day] => 0
                [monthnum] => 0
                [year] => 0
                [w] => 0
                [category_name] =>
                [tag] =>
                [cat] =>
                [tag_id] =>
                [author_name] =>
                [tb] =>
                [paged] => 0
                [comments_popup] =>
                [meta_key] =>
                [meta_value] =>
                [preview] =>
                [s] =>
                [sentence] =>
                [fields] =>
                [menu_order] =>
                [category__in] => Array
                    (
                    )
    
                [category__not_in] => Array
                    (
                    )
    
                [category__and] => Array
                    (
                    )
    
                [post__in] => Array
                    (
                    )
    
                [post__not_in] => Array
                    (
                    )
    
                [tag__in] => Array
                    (
                    )
    
                [tag__not_in] => Array
                    (
                    )
    
                [tag__and] => Array
                    (
                    )
    
                [tag_slug__in] => Array
                    (
                    )
    
                [tag_slug__and] => Array
                    (
                    )
    
            )
    
        [tax_query] =>
        [meta_query] =>
        [post_count] => 0
        [current_post] => -1
        [in_the_loop] =>
        [comment_count] => 0
        [current_comment] => -1
        [found_posts] => 0
        [max_num_pages] => 0
        [max_num_comment_pages] => 0
        [is_single] => 1
        [is_preview] =>
        [is_page] =>
        [is_archive] =>
        [is_date] =>
        [is_year] =>
        [is_month] =>
        [is_day] =>
        [is_time] =>
        [is_author] =>
        [is_category] =>
        [is_tag] =>
        [is_tax] =>
        [is_search] =>
        [is_feed] => 1
        [is_comment_feed] => 1
        [is_trackback] =>
        [is_home] =>
        [is_404] =>
        [is_comments_popup] =>
        [is_paged] =>
        [is_admin] =>
        [is_attachment] =>
        [is_singular] => 1
        [is_robots] =>
        [is_posts_page] =>
        [is_post_type_archive] =>
        [query_vars_hash] => 7832e8aa476657087351138dffd158ec
        [query_vars_changed] =>
        [thumbnails_cached] =>
        [query] => Array
            (
                [feed] => feed
                [school] => lycee-francais
                [post_type] => school
                [name] => lycee-francais
            )
    
    )
    testing

    Plugin Author Rachel Carden

    @bamadesigner

    Is the post type called ‘school’ or ‘schools’?

    Jeff

    @jhanbycarrolltongroupcom

    ‘school’

    I noticed that too, so I changed the rewrite rule to the following, but it still shows up empty.

    add_action( 'wp_loaded', 'largo_child_rewrite_rules' );
    function largo_child_rewrite_rules() {
       add_rewrite_rule( '^school/([^\/]+)/feed/?$','index.php?feed=feed&school=$matches[1]&cpt_onomy_archive=1', 'top' );
    }
    Plugin Author Rachel Carden

    @bamadesigner

    what’s the query after the change?

    Jeff

    @jhanbycarrolltongroupcom

    WP_Query Object
    (
        [query_vars] => Array
            (
                [feed] => feed
                [school] => lycee-francais
                [post_type] => school
                [name] => lycee-francais
                [error] =>
                [m] => 0
                [p] => 0
                [post_parent] =>
                [subpost] =>
                [subpost_id] =>
                [attachment] =>
                [attachment_id] => 0
                [static] =>
                [pagename] =>
                [page_id] => 0
                [second] =>
                [minute] =>
                [hour] =>
                [day] => 0
                [monthnum] => 0
                [year] => 0
                [w] => 0
                [category_name] =>
                [tag] =>
                [cat] =>
                [tag_id] =>
                [author_name] =>
                [tb] =>
                [paged] => 0
                [comments_popup] =>
                [meta_key] =>
                [meta_value] =>
                [preview] =>
                [s] =>
                [sentence] =>
                [fields] =>
                [menu_order] =>
                [category__in] => Array
                    (
                    )
    
                [category__not_in] => Array
                    (
                    )
    
                [category__and] => Array
                    (
                    )
    
                [post__in] => Array
                    (
                    )
    
                [post__not_in] => Array
                    (
                    )
    
                [tag__in] => Array
                    (
                    )
    
                [tag__not_in] => Array
                    (
                    )
    
                [tag__and] => Array
                    (
                    )
    
                [tag_slug__in] => Array
                    (
                    )
    
                [tag_slug__and] => Array
                    (
                    )
    
            )
    
        [tax_query] =>
        [meta_query] =>
        [post_count] => 0
        [current_post] => -1
        [in_the_loop] =>
        [comment_count] => 0
        [current_comment] => -1
        [found_posts] => 0
        [max_num_pages] => 0
        [max_num_comment_pages] => 0
        [is_single] => 1
        [is_preview] =>
        [is_page] =>
        [is_archive] =>
        [is_date] =>
        [is_year] =>
        [is_month] =>
        [is_day] =>
        [is_time] =>
        [is_author] =>
        [is_category] =>
        [is_tag] =>
        [is_tax] =>
        [is_search] =>
        [is_feed] => 1
        [is_comment_feed] => 1
        [is_trackback] =>
        [is_home] =>
        [is_404] =>
        [is_comments_popup] =>
        [is_paged] =>
        [is_admin] =>
        [is_attachment] =>
        [is_singular] => 1
        [is_robots] =>
        [is_posts_page] =>
        [is_post_type_archive] =>
        [query_vars_hash] => 7832e8aa476657087351138dffd158ec
        [query_vars_changed] =>
        [thumbnails_cached] =>
        [query] => Array
            (
                [feed] => feed
                [school] => lycee-francais
                [post_type] => school
                [name] => lycee-francais
            )
    
    )
    testing
Viewing 15 replies - 1 through 15 (of 26 total)
  • The topic ‘[Resolved] RSS Feed parameters’ is closed to new replies.
Skip to toolbar