Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #623211

    Hi currently the search page showing all the results but it displaying posts (portfolio, other post types) result first then the page result so i want to display the wordpress page that contain the search keyword result first then the posts that contain search keyword.

    #624925

    Hi,

    Can you post the link to your website please?

    Regards,
    Josue

    #625474

    Hi please find the link below

    #625508

    Hi,

    Since enfold only uses the default wordpress search you would need to use a plugin to do something like that. Its unfortunately quite hard to group the search results as you would require it (the wordpress default ist to mix those and list them by date) so I dont think there is a simple code snippet that we can offer that fixes this for you.

    However, some of the more advanced search plugins might work fine for you. eg:
    https://wordpress.org/plugins/relevanssi/

    It states that it can sort results by relevance and not by date, which might work fine for you ;)

    Best regards,
    Kriesi

    #625527

    Thanks for the reply but if you are using default wordpress search then why post coming up it can be pages or else is there any custom query or is there any way to modify search query.

    #625558

    Hi,

    The default query sorts all entries based on the date. You can of course try to use a snippet like this in your themes/child themes functions.php but I consider not messing with it and using a plugin the better option.

    But feel free to try this, I found it on stackoverflow, maybe it works as you want it :)

    add_filter( 'posts_clauses', 'post_query_order', 20, 1 );
    function post_query_order( $pieces )
    {
        global $wpdb;
        $pieces['orderby'] = $wpdb->prefix.'posts.post_type ASC';
        return $pieces;
    }
    

    Best regards,
    Kriesi

    #626954

    Hi the above code still not full filling the requirement more over the code is affecting over all site. I want to modify the query only for the search result.

    #627065

    Hi,

    You can try something like, this:

    add_filter( 'posts_clauses', 'post_query_order', 20, 1 );
    function post_query_order( $pieces )
    {
    if(is_search()){
        global $wpdb;
        $pieces['orderby'] = $wpdb->prefix.'posts.post_type ASC';
    }
        return $pieces;
    }
    

    Best regards,
    Kriesi

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.