Hi @xd1704 and @hwk-fr,
Thank you for your message. I don’t know exactly how your plugin works, but I will try to help you.
I base my plug on the original ACF structure. By default ACF plugin has this structure in the wp_postmeta table:
-----------------------------------------------------------
| meta_id | post_id | meta_key | meta_value |
------------------------------------------------------------
| 1000 | 100 | product_title | Lorem ipsum dolor |
| 1001 | 100 | _product_title | field_5d89bb00fc4a7 |
In addition, based on the value of field _...
I look in the wp_posts table for information about the field. When using Lite mode
, we only take into account the wp_postmeta table.
Below I explain how the SQL query works. Divide them into fragments accordingly.
Searching for records in the wp_posts table:
SELECT DISTINCT wp_l2w_posts.* FROM wp_l2w_posts
Searching for values in the wp_postmeta table:
INNER JOIN wp_l2w_postmeta AS a ON (a.post_id = wp_l2w_posts.ID)
Searching for an equivalent in the wp_postmeta table (note the correct data structure in the database):
LEFT JOIN wp_l2w_postmeta AS b ON (((b.meta_id = a.meta_id + @@auto_increment_increment)) AND ((b.meta_key LIKE CONCAT('\_', a.meta_key))))
Searching for information about the ACF field in the wp_posts table (not used in Lite mode):
LEFT JOIN wp_l2w_posts AS c ON ((c.post_name = b.meta_value) AND (c.post_type = 'acf-field') AND ((c.post_content LIKE '%:"text"%') OR (c.post_content LIKE '%:"textarea"%') OR (c.post_content LIKE '%:"wysiwyg"%')))
Default part of the query:
WHERE 1=1 AND (
Searching for a phrase in the wp_postmeta table:
((b.meta_id IS NOT NULL) AND (c.ID IS NOT NULL) AND (a.meta_value LIKE '%Lorem%'))
Searching for a phrase as WordPress does by default:
OR ((wp_l2w_posts.post_title LIKE '%Lorem%') OR (wp_l2w_posts.post_content LIKE '%Lorem%') OR (wp_l2w_posts.post_excerpt LIKE '%Lorem%'))
Default part of the query:
) AND wp_l2w_posts.post_type = 'blog' AND (wp_l2w_posts.post_status = 'publish' OR wp_l2w_posts.post_status = 'acf-disabled' OR wp_l2w_posts.post_status = 'future' OR wp_l2w_posts.post_status = 'draft' OR wp_l2w_posts.post_status = 'pending' OR wp_l2w_posts.post_status = 'private') ORDER BY wp_l2w_posts.post_title LIKE '%Lorem%' DESC, wp_l2w_posts.post_date DESC LIMIT 0, 20
If you have a structure other than the default one in the ACF plugin, the query will not work properly.
Can I help you somehow?