I’ve built a custom theme from scratch for a client and have a few custom post types. For one in particular, FAQ, I wanted to hide it from showing individual posts (posts would only appear on its archive page) and I hid it from searches using
‘exclude_from_search’ => true
Before I did this it was appearing in searches. I later decided to redirected clicks on single posts to the archive page and allow it to be included in searches. I changed the above value back to false but now they still don’t appear in a search. I’ve cleared my cache, I’ve tried this on the local and live site.

I’m using Ivory Search plugin but I’ve double checked all the setting to ensure that it’s not filtering out that post type. I even disabled it and used the native WP search option but the results are the same.

I’ve toggled the ‘exclude_from_search’ value on other custom post types and it works as expected. I can’t figure out what I’m missing with this particular post-type. Here is the code in my functions.php file:

function company_custom_post() {
register_post_type('faqs', array(
        'supports' => array('title', 'editor', 'author'),
        'public' => true,
        'exclude_from_search' => false,
        'show_in_rest' => true,
        'has_archive' => true,
        'labels' => array(
            'name' => 'FAQs',
            'add_new' => 'Add New FAQ',
            'add_new_item' => 'FAQ',
            'edit_item' => 'Edit FAQ',
            'all_items' => 'All FAQs',
            'singular_name' => 'FAQ'
         ),
         'menu_icon' => 'dashicons-editor-help'
    ));
}
add_action('init', 'company_custom_post');

On the archive-faqs.php here is the main php:

<?php
        $terms = get_terms('faq_category');
        foreach($terms as $term) : ?>
            <div class="faq-category">
                <h2><?php echo $term->name;?></h2>
            </div>
            <div class="faq-list">
                <?php
                // get all FAQ posts for each category
                $faqs = new WP_Query(array(
                    'post_type' => 'faqs',
                    'order' => 'DESC',
                    'tax_query' => array(
                        array(
                            'taxonomy' => 'faq_category',
                            'field' => 'name',
                            'terms' => $term->name
                        ),
                    ),
                ));

                while($faqs->have_posts() ) :   
                    $faqs->the_post(); ?>
                    <div class="faq-single">
                        <div class="single-faq-title">
                            <p><?php the_title(); ?></p>
                            <img class="expand toggle-answer" src="<?php echo get_template_directory_uri() . '/images/icons/expand.png';?>" alt="plus icon">
                            <img class="minimize toggle-answer" src="<?php echo get_template_directory_uri() . '/images/icons/minimize.png';?>" alt="minus icon">
                        </div>
                        <hr>
                        <div class="faq-answer"><?php the_content(); ?></div>
                    </div>
                    <?php endwhile; ?>
                    <?php wp_reset_query(); ?>
            </div>
        
        <?php endforeach; ?>

Any help or suggestions would be greatly appreciated. I wrote the code a while back and am just revisiting it to make the changes but I’m failing to see why it’s not working. Thanks!

0

Leave a Reply

Your email address will not be published. Required fields are marked *