Forums › Forums › Search & Filter Pro › Define posts to display first using custom fields
- This topic has 3 replies, 2 voices, and was last updated 7 years, 11 months ago by
Trevor.
-
Anonymous(Private) March 17, 2017 at 7:59 pm #97607
Hi, I have about 15 artists to display in the search results, and I’d like to be able to define one of the “best” or most representative pieces of art to display first for each artist, even after more posts continue to be added, so that they don’t get lost in the mix. This would be very useful in the first look at the search form, where no filters have been applied, as well as in a very broad search, where one search term results in several artists, with dozens of examples each.
I have custom fields working in the results.php already, so the image results can link directly to the artist page defined in the custom field, like this:
<?php if ( has_post_thumbnail() ) { ?> <span class="responsive"><a href="<?php echo get_post_meta($query->post->ID,'artistpage',true); ?>">
It seems like I should also be able to say, “display featured results first, then display as usual.” Do you think this is possible?
Liz
Anonymous(Private) March 25, 2017 at 11:16 am #99406Hi, I took some time to play around with the primary and secondary sort keys, and I had some unexpected results. I set the primary sort to “Random order / Descending,” and then set the Secondary sort to “Meta value / ascending / featuredproject / numerical”. I set a post to the custom field “featured project / 1”. The result was that when I input the first search filter, the result was random with no featured project first, and when I clicked refresh, it was filtered down to only the single featured project. (I was hoping to highlight the featured projects first in the results, and then show all the rest afterwards in random order).
I’m not sure if I set this up correctly, so let me know if there is a better way to try. I’d be willing to try manipulating other filters to accomplish this.
Thanks for helping me understand how the filter works,
Liz
Trevor(Private) March 25, 2017 at 11:26 am #99408Be wary of using random order, as posts can be repeated across pages, as the content of each page is random. WordPress does not randomly sort the posts and then give them to you page after page. It random sorts them again and again for each page, and thus pagination becomes pointless.
Also, numerous plugins and themes have been known to override sorting, so be aware that such interference can happen.
-
AuthorPosts