Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Featured Entries to the Top is breaking the Search (again) #1308

Closed
rafaehlers opened this issue Apr 30, 2019 · 14 comments
Closed

Move Featured Entries to the Top is breaking the Search (again) #1308

rafaehlers opened this issue Apr 30, 2019 · 14 comments
Assignees

Comments

@rafaehlers
Copy link
Contributor

rafaehlers commented Apr 30, 2019

When this option was checked (Move Featured Entries to the Top), the search results are incorrect.

GV 2.3.1 and FE 2.0.3

@rafaehlers rafaehlers added the Bug label Apr 30, 2019
@rafaehlers
Copy link
Contributor Author

@soulseekah
Copy link
Contributor

This has probably been fixed in https://github.com/gravityview/Featured-Entries/pull/27

Please confirm and close.

@zackkatz
Copy link
Member

@rafaehlers Can you please test?

@zackkatz
Copy link
Member

zackkatz commented Oct 7, 2019

@rafaehlers @jlgrisham Please test.

@zackkatz zackkatz assigned rafaehlers and ghost Oct 7, 2019
@rafaehlers
Copy link
Contributor Author

Sorry, I forgot to mention this was tested and fixed already.

@zackkatz zackkatz closed this as completed Oct 8, 2019
@bennemann
Copy link

bennemann commented Apr 1, 2020

It seems "Move Featured Entries to the Top" is still breaking the search.

If "Move Featured Entries to Top" is checked on the settings of a View, you can't combine an Advanced Filter condition and a Search Bar filter. You can have them separately, but not combined.

Steps to reproduce:

  1. Have "Move Featured Entries to the Top" checked on a View.
  2. Add a Search Bar (any) and an Advanced Filter condition (any).
  3. Try to search.

You'll get an SQL error about an unknown column. In fact, the problem is that it tries to access the column using an unset alias.

Here's an example:

WordPress database error: [Unknown column 'm3.meta_value' in 'where clause']
SELECT SQL_CALC_FOUND_ROWS DISTINCT `t1`.`id` FROM `wp_gf_entry` AS `t1` LEFT JOIN `wp_gf_entry_meta` AS `m2` ON (`m2`.`entry_id` = `t1`.`id` AND `m2`.`meta_key` = 2) WHERE (`t1`.`form_id` IN (9) AND ((`t1`.`status` = 'active' AND (`m2`.`meta_key` = 2 AND `m2`.`meta_value` = 'test')) AND `m3`.`meta_value` LIKE '%test%')) ORDER BY `t1`.`is_starred` DESC, `t1`.`id` DESC LIMIT 25

GV 2.7.1 and FE 2.0.5

@bennemann bennemann reopened this Apr 1, 2020
@bennemann bennemann unassigned ghost Apr 1, 2020
@zackkatz zackkatz assigned soulseekah and unassigned rafaehlers Apr 7, 2020
@soulseekah
Copy link
Contributor

soulseekah commented Apr 21, 2020

  1. Add a Search Bar (any) and an Advanced Filter condition (any).

This actually works fine. Having an Any/Everything restriction has the correct SQL generated.

In the example error the Advanced Filter was set to field ID 2. So the correct way to reproduce it is to set explicit fields for either the Search Bar or the AF (or both).

It also works if you have two different field AF conditions, as the second missing join is actually generated (m3). So looks like the Search bar is not generating its own join as needed.

But this only happens when Move To Top is selected, the join actually gets merged:

image

What we do in GravityView_Featured_Entries::gf_query_filter is grab a nested condition from the original query and reproduce it in a new query. But the new query is not generating the joins correctly. Why?

image

Because the Search condition has a remnant forced alias! Doh.

image

The solution would be to either strip the aliases from the conditions that we're copying over, or keep the original query intact and tack the featured order clause onto it instead of doing this substitution. The latter is not possible though, as the order() calls push clauses onto a stack, so you can't set featured to be the highest-priority order :(

So alias-stripping then, eh?

This is something we did discuss with Steven in our latest meeting back in February - how it's difficult to change the where and order clauses without copying them over to a new GF_Query object, remember?

@soulseekah
Copy link
Contributor

Fixed by creating a stripping utility method and utilizing it inside the Featured Entries plugin. Please test and let me know.

This may need some unit tests.

Cheers.

@rafaehlers
Copy link
Contributor Author

@rafaehlers rafaehlers reopened this Aug 4, 2020
@rafaehlers
Copy link
Contributor Author

@mrcasual
Copy link
Collaborator

mrcasual commented Sep 8, 2020

@soulseekah f5e79fa and https://github.com/gravityview/Featured-Entries/commit/9e9b5e62f8e584b8aefd9d45a021a788ff7b6f6a break the search when a filter condition contains a multi-input field.


...meta_key should have a LIKE operator. Could you please look into this?

@rafaehlers
Copy link
Contributor Author

@bennemann
Copy link

@mrcasual mrcasual assigned mrcasual and unassigned soulseekah Apr 29, 2021
@mrcasual
Copy link
Collaborator

Fixed by https://github.com/gravityview/Featured-Entries/releases/tag/v2.0.7

Time to close this sucker :) 🎆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants