Assigned categories to pages, Relevanssi not taking page categories into account
-
I’m trying to seperate my search results into 3 sections: Pages, Case Studies, and Profiles.
I’m using the following loop in order to achieve this:
<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <?php if ($post->post_type == 'page') : ?> Pages output here <?php endif; ?> <?php endwhile; ?> <?php rewind_posts(); ?> <?php while (have_posts()) : the_post(); ?> <?php if ($post->post_type == 'case-study') { ?> Case Studies output here <?php } ?> <?php endwhile; ?> <?php rewind_posts(); ?> <?php while (have_posts()) : the_post(); ?> <?php if ($post->post_type == 'profiles') { ?> Profiles output here <?php } ?> <?php endwhile; ?> <?php rewind_posts(); ?> <?php else : ?> No Results <?php endif; ?>
The loop is working perfectly I think, but if anyone has any suggestions as to how to improve it, I’m all ears =).
My issue is, I’ve used a function in order to assign the default WordPress categories to my pages, and Relevanssi doesn’t seem to be taking these categories into account when performing the search. It searches the categories assigned to the case studies and profiles, but not the page categories.
The method I’ve used in order to assign the categories to pages is as follows:
//Add categories to pages function add_taxonomies_to_pages() { register_taxonomy_for_object_type( 'post_tag', 'page' ); register_taxonomy_for_object_type( 'category', 'page' ); } add_action( 'init', 'add_taxonomies_to_pages' ); if ( ! is_admin() ) { add_action( 'pre_get_posts', 'category_and_tag_archives' ); } function category_and_tag_archives( $wp_query ) { $my_post_array = array('post','page'); if ( $wp_query->get( 'category_name' ) || $wp_query->get( 'cat' ) ) $wp_query->set( 'post_type', $my_post_array ); if ( $wp_query->get( 'tag' ) ) $wp_query->set( 'post_type', $my_post_array ); }
Is there anything I can do in order to make Relevanssi take the page categories into account and include the correct results in the first section of my loop?
- The topic ‘Assigned categories to pages, Relevanssi not taking page categories into account’ is closed to new replies.