Untitled
unknown
php
3 years ago
663 B
9
Indexable
function grid_query_include_post_ids( $query_args, $grid_id ) {
global $post;
// If it matches grid id 1.
if ( 17 === $grid_id ) {
// The grid is also queried during Ajax requests when filtering or rendering facets.
// So we have to get the ID of the current post/page thanks to the referer.
$referer = wp_get_referer();
$post_id = wp_doing_ajax() ? url_to_postid( $referer ) : $post->ID;
// You have to change "custom_field_name" by yours.
$query_args['post__in'] = (array) get_post_meta( $post_id, 'custom_field_name', true );
}
return $query_args;
}
add_filter( 'wp_grid_builder/grid/query_args', 'grid_query_include_post_ids', 10, 2 );Editor is loading...