#23475 closed defect (bug) (worksforme)
Feed querystring not limiting returned posts by post type when also using category
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 3.5.1 |
Component: | Query | Keywords: | close |
Focuses: | Cc: |
Description
I set up an example to demonstrate what's happening: http://demo.jarrodpyper.com/feed/?post_type=syndicated&category_name=craft
This feed *should* only return the one post on my site, "test syndicate" that is in the "Syndicated" post type and also in the "craft" category. Instead the post titled "post" of the default "post" post_type is being returned in the feed as well because it is also in the "craft" category.
This works correctly within a normal page using query_posts, which I thought would be similar if not the same as the way the querystring was handled when put into the URL.
Not sure if "Query" or "Feed" is the more relevant component keyword to use here.
Change History (4)
#2
@
12 years ago
- Keywords reporter-feedback removed
Alright, I flushed rewrite rules (visited permalinks page) and checked again, still the same.
I did the var_dump and sure enough, it's querying "post" and "syndicated" both: ["post_type"]=> array(2) { [0]=> string(4) "post" [1]=> string(10) "syndicated" }
If you want to see the whole dump of query_vars you can visit the link in the original post. I just hooked into rss2_head and dumped there.
If (via querystring in the URL) I go after just post_type=syndicated, I only get that post type, but when I throw the category in there I get both "post" as well.
Edit: This is how I have set up my post type, in case it matters.
`function register_v_syndicated_content() {
$labels = array(
'name' => _x( 'Syndicated Content', 'syndicated' ),
'singular_name' => _x( 'Syndicated Content', 'syndicated' ),
'add_new' => _x( 'Add New', 'syndicated' ),
'add_new_item' => _x( 'Add New Syndicated Content', 'syndicated' ),
'edit_item' => _x( 'Edit Syndicated Content', 'syndicated' ),
'new_item' => _x( 'New Syndicated Content', 'syndicated' ),
'view_item' => _x( 'View Syndicated Content', 'syndicated' ),
'search_items' => _x( 'Search Syndicated Content', 'syndicated' ),
'not_found' => _x( 'No syndicated content found', 'syndicated' ),
'not_found_in_trash' => _x( 'No syndicated content found in Trash', 'syndicated' ),
'parent_item_colon' => _x( 'Parent syndicated content:', 'syndicated' ),
'menu_name' => _x( 'Syndicated', 'syndicated' ),
);
$args = array(
'labels' => $labels,
'description' => 'This content is all imported. Changes made to it will prevent it from receiving updates',
'public' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_nav_menus' => true,
'show_in_menu' => true,
'show_in_admin_bar' => true,
'menu_position' => '5',
'menu_icon' => ,
'capability_type' => 'page',
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'excerpt', 'page-attributes', 'comments'),
'register_meta_box_cb' => 'v_syndicated_metaboxes',
'taxonomies' => array( 'category' ),
'has_archive' => true,
'rewrite' => array('slug' => 'info', 'with_front' => false),
'query_var' => true,
'can_export' => true
);
register_post_type( 'syndicated', $args );
}
add_action( 'init', 'register_v_syndicated_content' );`
#3
@
11 years ago
- Milestone Awaiting Review deleted
- Resolution set to worksforme
- Status changed from new to closed
Can you update to 3.9 and see if this is still an issue? I just used your example against trunk and everything is working correctly.
Reopen if this is reproducible in your environment, and please explain any modifications you have made. Also, turn off your modifications when testing initially to determine if the theme or plugin is causing this error.
#4
@
11 years ago
Well, I'm 10 months more experienced than I was when I reported this as a bug. I was able to find that the real reason for this happening was my own code. In order to get my custom post type to show up in archives along with posts, I've hooked into pre_get_posts and checked for is_archive() and is_category() before changing the query's post type to... wait for it... array('post', 'syndicated')
I did not realize that this would affect a feed. Adding in an is_feed() check to NOT do this fixed the problem.
Thanks for your help and follow up, sorry for the time waster :(
I can't reproduce this. Can you flush your rewrite rules and try again? Also, maybe supply a var_dump of the global
$wp_query->query_vars