• When i use the search bar included in the OceanWP theme, my custom post types are not included.
    If I change the URL after a search action, from domain.com/?s=searchterm to domain.com/?s=searchterm&post_type=customposttype, it displays only the search results for this custom post type. So my custom post type is visible but wont get included for some reason in the searchresults.

    How can i solve this?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello,

    Add the below code to the functions.php file of the oceanwp child theme and check it fixes the issue or not –

    function add_custom_post_type_to_query( $query ) {
        if(is_single() || is_page() || is_admin()) {
            return;
        }
        if ( $query->is_main_query() ) {
            $query->set( 'post_type', array('post', 'cpt-1', 'cpt-2') );
        }
    }
    add_action( 'pre_get_posts', 'add_custom_post_type_to_query' );
    Thread Starter pieterttn

    (@pieterttn)

    Hey @apprimit

    Thanks for your reply.

    I replaced cpt-1 and cpt-2 with the correct term for my CPT’s
    Unfortunately it doesn’t solve the issue, there is a change tho in the results that are returned. On first sight there is already a shift in the posts we link to a post of the CPT.

    Could it be that I am missing something in the CPT settings?
    But then again they are returned if i add ‘&post_type=customposttype’ to the url in the address bar after a search

    Can you link to your site after adding the code?

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Custom Post Types dont show up in search results’ is closed to new replies.