-
Notifications
You must be signed in to change notification settings - Fork 37
Re-implement logic for previewing WP_Query and introduce non-multiple postmeta #248
Conversation
foreach ( $table_fields as $field_name => $type ) { | ||
$select_field = sprintf( | ||
'CAST( %s AS %s) AS %s', | ||
$wpdb->prepare( '%s', $postmeta_row[ $field_name ] ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@westonruter Not accepting a case when $meta_value
is an array. (Takes fist value and ignores other.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@PatelUtkarsh isn't that handled by the building up of the $postmeta_rows
array above? It checks if it is not single, and of not, it iterates over each of the meta values to then add as separate rows here.
- One deficiency I do notice, however, is that it needs to
maybe_serialize()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@westonruter oh my bad I didn't declare it single => false
@PatelUtkarsh so you could integrate with the project by adding |
@westonruter I passed it in |
@PatelUtkarsh that will work too. I'm trying to figure out if it makes more sense for the |
@westonruter I can not think of a use-case where I would need all multi-post meta values together for the filter. Maybe to limit the multi-meta or removing duplication but that can be handled by control. Edit: Ordering of multiple-meta? Sync post meta code does not preserve order. |
Fixes failure to union selects due to mismatched collations * Move `maybe_serialize()` to postmeta instead of post data. * Move field mention checks outside of loop. * Omit exporting any customized TEXT fields unless they are mentioned. * Eliminate unnecessary placeholder_meta_id, replacing with NULL.
The above would require re-deriving the post types being queried if
|
Comparing some queries with and sans the customized data injected: https://gist.github.com/westonruter/36563b2356a7a3c891f178176fc99b3a |
…nto feature/query-preview-refactor
…nto feature/query-preview-refactor
…nto feature/query-preview-refactor
Creating postmeta settings for posts that have negative post IDs does not work because get_post_meta() uses absint() on the post ID
@PatelUtkarsh let me know when you're confident this can be merged. |
@westonruter Should I update the code for preserve an order of plural postmeta? |
@PatelUtkarsh I'm leading towards no. It's current behavior for the order to not be stable in the entities plugin, right? As such, making the order stable would be an enhancement. But if you think otherwise, please do amend the PR with persistent ordering. |
@westonruter Are you suggesting the order in the Select2 is an enhancement? |
@valendesigns this is about the order in which the plural postmeta are written into the database, whether existing postmeta which are unchanged should be deleted so that they can be reinserted with a |
@PatelUtkarsh please connect with @sayedwp and @miina as the ordering of the plural postmeta may indeed be what is affecting the ordering of repeater controls. If so, then we should simplify the |
@westonruter There is no such need for preserving order right now, Even in repeater control we don't need the order of plural post-meta as we are storing it in serialize for ordering and grouping(because grouping is difficult with plural post-meta). If any special case arises we can handle it by overriding update method as you mentioned. |
This introduces a somewhat radical approach to getting customized data to appear as expected in previewed post queries: the customized data is
UNION
'ed with thewp_posts
andwp_postmeta
table via inline literalSELECT
s which then serve as a subselect for the main select which gets the results. The effect is that we can rely on MySQL as normal to handle all of the variousWP_Query
vars, including any Meta Queries that may be thrown at it.This fixes what the #247 PR set out to do, which was to hackily force a customized post to appear on the first page of results (even if it doesn't belong there). By going deep into the MySQL query to inject the customized data, it seems that we get complete support for WP Query, amazingly. It's still hard to believe that this works and I want to consider this experimental and get testing on it.
Fixes #246
Non-single (multiple) postmeta is credited to @PatelUtkarsh.
the_posts
filter to apply as early as possible since post fields will get hydrated there sinceSELECT
literals will omit data not needed.customize_previewed_postmeta_rows
filter to allow meta to be filtered before being injected into a query:wp-customize-posts/php/class-wp-customize-posts-preview.php
Line 551 in 91b62a8
fields => ids
is used.customize_previewed_posts_for_query
filter can indeed be removed.Consider reversing the order of theUNION
s so that customized posts will be returned first if a list of posts have identical values toorderby
, as then the sorting becomes unstable, and the same order would not be previewed. This is an edge case.