• Resolved Matteo

    (@matteofeduzi)


    Hello,

    SCP changes the order of my results from a given search.

    I’m trying this code to force “relevance”, but it still doesn’t work quite right:

    function searchfilter($query) {
    if ($query->is_search && !is_admin() && $query->is_main_query())
    {
    $query->set('post_type',array('page', 'post'));
    $query->set('orderby', array('relevance' => 'ASC'));
    }
    return $query;
    }
    add_filter('pre_get_posts','searchfilter');

    Thank you.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @matteofeduzi,

    As much as I would like to help, this is not a native option the plugin has at the moment. It will display the posts in the selected order.

    However, it’s possible though that someone on these forums might’ve already tried what you need and could help so we’ll leave the thread open for the time being.

    Warmly,

    Mihaela

    Marking this support thread as resolved due to inactivity. If you have any other questions or need further help please open a new thread.

    the support of ‘page-attributes’ is required to be first added to the post type generated manually, in order, to later call the ‘menu_order‘ directive. This directives allows the order to be done according to defined setting and not according to default post creation time.

    You may read more about it, here

    So the adding of the element to be controlled on functions.php would now look like this:

    function list_faq() {
        register_post_type('faq_questions',
            array(
                'labels' => array(
                    'name' => __('FAQ'),
                    'singular_name' => __('FAQ')
                ),
                'public' => true,
                'has_archive' => true,
                'supports' => array('title', 'editor', 'thumbnail', 'excerpt' , 'page-attributes')
            )
        );
    }
    
    add_action('init', 'list_faq');

    And the placing on the website of the fetched content would now look like this:

    <div class="tabcontent-box" id="id">
    	<ul class="ul-content">
    	<?php
    	$query = new WP_Query(array(
    		'post_type' => 'faq_questions',
    		'orderby' => 'menu_order',
    		'order' => 'ASC',
    		'tax_query' => array(
    			array(
    				'taxonomy' => $current_term->taxonomy,
    				'field' => 'slug',
    				'terms' =>	$current_term->slug
    
    			)
    		)
    	));
    	while ( $query->have_posts() ) : $query->the_post(); ?>
    		<li>
    			<a href="<?php the_permalink() ?>" class="tabcontent-link"><?php the_title() ?></a>
    		</li>
    	<?php endwhile; ?>
    	</ul>
    </div>

    And now… the magic returns, and moving by drag-and-drop of the elements with this plugin is back to working.

    You may also manually change the numbering of menu_order on the WordPress POST data base, according the post_type of the highlighted chosen by you name. This is required when you have more p

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Simple Custom Post Order changes search results’ is closed to new replies.