Forums Forums Search & Filter Pro Sorting post results in sf_edit_query_args

Tagged: , ,

Viewing 4 posts - 1 through 4 (of 4 total)
  • Anonymous
    #227761

    Hi there,

    So I have a list of reference IDs (ACF Field for each post) in an array which I use in a meta_query to filter posts further after search and filter does its thing. This array contains post references in a specific order and the order I would like the posts to display.

    Here is the query I am using:

    ‘paged’ => int 1
    ‘search_filter_id’ => int 47
    ‘search_filter_override’ => boolean false
    ‘posts_per_page’ => int 10
    ‘post_status’ =>
    array (size=1)
    0 => string ‘publish’ (length=7)
    ‘meta_query’ =>
    array (size=1)
    0 =>
    array (size=3)
    ‘key’ => string ‘post_reference’ (length=13)
    ‘value’ => ARRAY OF POST REFS HERE
    ‘compare’ => string ‘IN’ (length=2)
    ‘post_type’ => string ‘custom_post’ (length=8)
    ‘orderby’ => string ‘meta_value’ (length=10)`

    Now obviously we can’t override post__in which would be ideal as I can pass an aray of post IDS rather than references, is there no way whatsoever we can do this?

    I tried to order by the meta_value which is the array of post refs, but it just orders them alphabetically rather than in the order they are in the given in the array.

    Can you think of a way I can work with SAFP to get this working correctly?

    Thanks

    Trevor
    #227815

    Not to do a complex sort like that, no, because in the code you show, you are creating a very unique sort index.

    In a way, what you really need is some form of custom field already attached to the posts that has the correct sort order, but that is not possible, I presume?

    Anonymous
    #227909

    Hi Trevor and thanks for the reply, unfortunately not as the radius changes every time the user searches so cant be stored on a per post basis 🙁

    Looks like I may have to code a custom search instead.

    Is post__in completely out of the picture or is there a way to override this?

    Thanks

    Trevor
    #227917

    Sadly, you can’t use that, no.

Viewing 4 posts - 1 through 4 (of 4 total)