Tell us what you are trying to do?
I have a custom post type (locations) that uses a content template. Inside the content template, I want to create a view that lists 3 nearby locations. The locations are the same post type, kind of like related posts but author defined.
I'm using 3 select custom fields (Nearby Communities One, Nearby Communities Two, Nearby Communities Three) in the locations post type dynamically populated from the locations post list using this code:
add_filter( 'wpt_field_options', 'func_dynamic_populate', 10, 3);
function func_dynamic_populate( $options, $title, $type ){
switch( $title ){
case 'Nearby Communities One':
case 'Nearby Communities Two':
case 'Nearby Communities Three':
$options = array();
$args = array(
'post_type' => 'location',
'posts_per_page' => -1,
'post_status' => 'publish');
$posts_array = get_posts( $args );
foreach ($posts_array as $post) {
$options[] = array(
'#value' => $post->ID,
'#title' => $post->post_title,
);
}
break;
}
return $options;
This code works to populate the select fields so the author can choose their 3 nearby location posts.
I've created a view to display these posts in the content template, but I can't work out what the query filter in the view should look like. No matter what I do the view just shows the latest 3 posts rather than the ones defined in the select fields.
Is there any documentation that you are following?
Nope, can't find anything
Is there a similar example that we can see?
No
What is the link to your site?
hidden link <<example page, Nearby Communities section