I have added the custom post type to td_data_source
I added this code:
//init the array
$wp_query_args = array(
'ignore_sticky_posts' => 1,
'post_type' => array('post','reviews')
);
Now it works in most places, but not in archive area. Is there another file that I am missing that needs to be edited.
these sections show up in search and everything else, just not in the archive or Category pages for some reason.
Any ideas?
Hi,
Please try this filter in your theme functions file:
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if(is_category() || is_tag()) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('post','cpt'); // replace cpt to your custom post type
$query->set('post_type',$post_type);
return $query;
}
}
Hope this helps!
Thanks
Okay, that code worked and got it so all posts where showing. Although implementing that code, seems to give an odd error when in a category or archive section. Once activated posts display, but the menu also seems to show a selection of the posts rather then the categories. See here:
http://content.screencast.com/users/bfrye27/folders/Default/media/deb1df40-cd82-42f9-a61f-e835c1ba9f6b/oddmenu.jpg
Here is what it looks like in any other area of the site that is not a category:
http://content.screencast.com/users/bfrye27/folders/Default/media/329761ba-f8c1-46d6-8335-78a77f3ef1b0/normalmenu.jpg
Let me know your thoughts, it is possible I am missing a needed step
Hi,
Please also add 'nav_menu_item' along your custom post type, like this: http://screencast.com/t/sQSMDdurzS4
This should solve your problem.
Thanks
Okay, That is almost where we need it. It added back the regular menu, but it still seems to have all the other articles listed as well: http://screencast.com/t/FSXjyyrPUuw
So it is much better then the old one: http://content.screencast.com/users/bfrye27/folders/Default/media/deb1df40-cd82-42f9-a61f-e835c1ba9f6b/oddmenu.jpg
Any ideas what is missing? Maybe I am doing something wrong. Here is my code:
http://screencast.com/t/qHYyTBGVTt
Hi,
Please try adding this: http://screencast.com/t/uq0gYbRl ..add this line: && empty( $query->query_vars['suppress_filters'])
Let me know if you still get it like this.
Thanks
-
This reply was modified 11 years by
Lucian.
Okay, I tried that, did not seem to make any changes
Here is the code: http://screencast.com/t/ubdjqf1nW
and here is what the menu displays like now: http://screencast.com/t/2nkIsLbO
Is it possible there is something wrong with the way I have the code? I feel it should not be this hard.
Let me know your thoughts,
thanks again!
Hi,
Please also check this after adding brackets to category and tag conditions, like this: http://screencast.com/t/t3c8SzVsYVD
And also please let me know how did you added your custom post types as you might need to do additional customization to this.
You can find here more suggestions on how to achieve this, give them a try:
http://css-tricks.com/snippets/wordpress/make-archives-php-include-custom-post-types/
I also suggest you try to find a solution for this online or use a plugin for it.
Thanks
Okay, that fixed it!
The custom post type was added by the reviews system we use. It makes a new category named reviews, adds new fields etc. Sadly with so many reviews using it, it would be a rather large task to move everything over and would also break all the permalinks that are present.
Thanks so much for all your help!
It took me a little while to get everything working, So I thought I would ensure listed the final code incase anyone was running into the same issues.
The final code to ensure it displays everywhere is:
add_filter('pre_get_posts', 'query_post_type');
function query_post_type($query) {
if((is_category() || is_tag() || is_author()) && empty( $query->query_vars['suppress_filters'])) {
$post_type = get_query_var('post_type');
if($post_type)
$post_type = $post_type;
else
$post_type = array('post','cpt'); // replace cpt to your custom post type
$query->set('post_type',$post_type);
return $query;
}
}
-
This reply was modified 11 years by
bfrye26.
