Skip to main content
10 events
when toggle format what by license comment
Oct 18, 2017 at 13:34 comment added Randomer11 Sorry I probably confused things by answering, the code now works when the above mentioned Join/search code isnt loaded. So they both work as expected separately but not together.
Oct 18, 2017 at 13:28 comment added FluffyKitten @Randomer11 Yes I saw you had added an answer! I didn't get a chance to look into it yet. So you're still having problems? I thought is_tax solved it? I was actually looking at the code in your link when you answered, and the expectation would be that its is_search() and the is_main_query/is_post_type_archive check in this code would exclude one from affecting the other. I assume if you remove the search code, the sort is working (i.e. so we can rule out any other conflicts)?
Oct 18, 2017 at 13:09 comment added Randomer11 Ok found the conflict :) but unsure how to solve it as both functions is something I need, Its the left join ( first bit of code on this page thats causing the problem, so as you said there is multiple joins : adambalee.com/…
Oct 18, 2017 at 12:20 vote accept Randomer11
Oct 18, 2017 at 10:57 comment added FluffyKitten @Randomer11 Not right now, but I'll take a look later if you still haven't tracked down the issue!
Oct 18, 2017 at 10:44 comment added FluffyKitten @Randomer11 The code in my answer works with ACF because I use it myself, so I'm afraid you're going to have to troubleshoot your setup to find what's causing the duplicate wp_postmeta join. First, as wp_postmeta is already being joined, try removing the $query->set( 'meta_key', 'featured_listing' ); from the function above. Then try disabling all plugins to except ACF to test in any of those cause it, if that doesn't change anything, try using one of the default WP themes with nothing added but your CPT and the function above. If that still doesn't work then you might need to look at ACF.
Oct 18, 2017 at 10:35 comment added Randomer11 I use the standard loop in the templates so no additional queries at that point. I did see the ACF disabled which I didnt know what it represented. The post_meta ( featured_listing ) is created with ACF ( advanced custom fields )
Oct 18, 2017 at 10:15 comment added FluffyKitten Thats strange. I presume its because it is trying to join to the wp_postmeta twice: INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id. Are you using the standard Wordpress loop on your page that shows the posts, or a custom query using WP_Query (or other function)? Or do you have any other functions hooking into the query that could be including the postmeta table a second time?I see reference to acf-disabled in the query... what could be including posts with acf-disabled status, maybe its it?
Oct 18, 2017 at 10:07 comment added Randomer11 Thanks for your time with this, I've tried the above and it still didnt work in respects of reordering anything in categories, where was no errors either. However when using search, I got this error : WordPress database error: [Not unique table/alias: 'wp_postmeta'] SELECT SQL_CALC_FOUND_ROWS DISTINCT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id WHERE 1=1 AND (
Oct 18, 2017 at 8:58 history answered FluffyKitten CC BY-SA 3.0