griffinjt
Member
Posted 1 year ago #
My custom post type is not showing up in my search results or in my archives. I'm not really sure what to do here. For example, when I go to my category 'Portfolio', it does not return anything, even though I have have 2 custom posts in that category.
Anyone know what to do?
My website is http://thomasgriffinmedia.com
Hoping to get this resolved soon.
griffinjt
Member
Posted 1 year ago #
Ok, I figured out how to include them in the search results. I had forgotten that I had excluded pages from my search results, but I forgot to add in my custom post type for the search results.
However, my custom post types are still not appearing for my taxonomies. I'm just using the 'category' taxonomy for my custom post type, but when I go to the category page for my custom post type, nothing appears. Anyone know what to do here?
griffinjt
Member
Posted 1 year ago #
Anyone have any idea what do to?
griffinjt
Member
Posted 1 year ago #
Still haven't found a resolution to this. Any suggestions?
I'm also interested to find how to search custom post types.
griffinjt
Member
Posted 1 year ago #
Does anybody have any solution to this? You can view an example here:
http://thomasgriffinmedia.com/category/portfolio/
None of my custom post types show up, even though I have 2 in that category.
What needs to be done to fix this?
Jorge A. Gonzalez
Member
Posted 1 year ago #
Place
query_posts( array('post_type' => array('apps','posts'), 'cat' => $cat) );
Directly above
if (have_posts ()) :
This will pull the custom type apps in the category page. I'm sure you can do the same for tags.
griffinjt
Member
Posted 1 year ago #
Put that into my code, but still didn't work. :(
alanchrishughes
Member
Posted 1 year ago #
How did you include the custom post types in your searches?
griffinjt
Member
Posted 1 year ago #
I placed this code in my functions.php file:
function filter_search($query) {
if ($query->is_search) {
$query->set('post_type', array('post', 'folio'));
};
return $query;
};
add_filter('pre_get_posts', 'filter_search');
This will return results from my posts and from my custom post type called 'folio'. You should replace that with your custom post type(s) names. Also, this bit of code removes pages from search results, which is generally a good thing. :)
alanchrishughes
Member
Posted 1 year ago #
So if I had two or three custom post types I wanted to include as well as my pages, I would write it like this?
$query->set('post_type', array('post', 'pages', 'folio', 'newcustomposttype', 'anotherposttype'));
griffinjt
Member
Posted 1 year ago #
alanchrishughes
Member
Posted 1 year ago #
Do you know if it would be possible to apply this to just one search bar, while all the rest function normally?
balebond
Member
Posted 1 year ago #
Any luck with category/tags? When a user selects a tag I want all my tagged custom posts to show up on the archives page with blog entries. Right now, only post show although I have tags enabled and set for other custom post types.
Thanks.
I just add this as part of the array when creating a custom post type:
'query_var' => true,
chris
Member
Posted 10 months ago #
Does anyone have a solution to @alanchrishughes question? I have a search form on one page that I only want to search and output a specific post type.
toomanyairmiles
Member
Posted 8 months ago #