WordPress.org

Ready to get started?Download WordPress

Forums

How to Include Custom Post Types in Search Results and Archives (17 posts)

  1. Thomas Griffin
    Member
    Posted 3 years 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.

  2. Thomas Griffin
    Member
    Posted 3 years 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?

  3. Thomas Griffin
    Member
    Posted 3 years ago #

    Anyone have any idea what do to?

  4. Thomas Griffin
    Member
    Posted 3 years ago #

    Still haven't found a resolution to this. Any suggestions?

  5. dapro
    Member
    Posted 3 years ago #

    I'm also interested to find how to search custom post types.

  6. Thomas Griffin
    Member
    Posted 3 years 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?

  7. Jorge A. Gonzalez
    Member
    Posted 3 years 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.

  8. Thomas Griffin
    Member
    Posted 3 years ago #

    Put that into my code, but still didn't work. :(

  9. alanchrishughes
    Member
    Posted 3 years ago #

    How did you include the custom post types in your searches?

  10. Thomas Griffin
    Member
    Posted 3 years 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. :)

  11. alanchrishughes
    Member
    Posted 3 years 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'));

  12. Thomas Griffin
    Member
    Posted 3 years ago #

    That is correct. :)

  13. alanchrishughes
    Member
    Posted 3 years ago #

    Do you know if it would be possible to apply this to just one search bar, while all the rest function normally?

  14. balebond
    Member
    Posted 3 years 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.

  15. jfelton
    Member
    Posted 3 years ago #

    I just add this as part of the array when creating a custom post type:
    'query_var' => true,

  16. chris
    Member
    Posted 3 years 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.

  17. toomanyairmiles
    Member
    Posted 2 years ago #

    Chris, Kevin Chard has a great solution for locking the search to a single post type here: http://wpsnipp.com/index.php/template/create-multiple-search-templates-for-custom-post-types/

Topic Closed

This topic has been closed to new replies.

About this Topic