[Improvement] Post Custom Field Contains Current Post ID
-
We have a few client use cases where we are trying to create a Dynamic Related Posts list using the Post Custom Field Contains Current Post ID option. However the custom field is an ACF Post Object with multi-select enabled. This means multiple post IDs are stored in a serialized array instead of simply the one post ID. We’ve slight adjusted the code to account for this option. This works for WordPress 3.7 and above.
Edit file: advanced-post-queries/queries/module.php
around line 511
Replace this:$meta_query[] = [
'key' => $settings[ 'postid_parent' ],
'compare' => '==',
'value' => $post_id,
];with this:
$meta_query[] = [
'relation' => 'OR',
[
'key' => $settings['postid_parent'],
'value' => $post_id,
'compare' => '=',
],
[
'key' => $settings['postid_parent'],
'value' => sprintf('s:[0-9]+:"%d";', $post_id),
'compare' => 'REGEXP',
],
];So far it seems to work well.
@shabti @dynamiapps can you verify and possibly add this to the core?
- You must be logged in to reply to this topic.