I have used this same code on my site:
https://toolset.com/forums/topic/populate-select-field-with-list-of-posts-in-a-custom-post-type/
to create a dropdown field that displays custom post types within the field, but only 5x items appear in the dropdown and there should be 9. No matter what I do it only shows the last 5 custom posts.
Link to a page where the issue can be seen: hidden link (day 1, day 2 fields etc. show this and you need to be logged in)
This is the code I was referring to.
add_filter( 'wpt_field_options', 'populate_select_1_1', 10, 3);
function populate_select_1_1( $options, $title, $type ){
switch( $title ){
case 'Person 1 Day 1 - Selection':
$options = array();
$args = array(
'post_type' => 'recipe',
'post_status' => 'publish',
'tax_query' => array(
array (
'taxonomy' => 'recipe-category',
'field' => 'slug', // term_id, slug or name
'terms' => 'this-weeks-recipes'
)
)
);
$posts_array = get_posts( $args );
foreach ($posts_array as $post) {
$options[] = array(
'#value' => $post->ID,
'#title' => $post->post_title,
);
}
break;
}
return $options;
}
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
Well - I simply am not able to access the link you share and when I try to load it, it displays error on the browser:
Could you please send me working site as well as double check that access details you send me for wp-admin working.
Hi, our server does not like incoming connections from India. Please use a proxy or get another supporter from a different area to try.
Hi, Is there anyone who can help?
Hi Johan,
Thank you for waiting, while I looked into the details you've shared.
By default, the "get_posts" function ( https://codex.wordpress.org/Template_Tags/get_posts ), returns 5 results, when "numberposts" or "posts_per_page" parameter is not set.
To make sure that all posts matching the criteria are used for the drop-down options, you can include "'posts_per_page' => -1," in your code:
add_filter( 'wpt_field_options', 'populate_select_1_1', 10, 3);
function populate_select_1_1( $options, $title, $type ){
switch( $title ){
case 'Person 1 Day 1 - Selection':
$options = array();
$args = array(
'post_type' => 'recipe',
'posts_per_page' => -1,
'post_status' => 'publish',
'tax_query' => array(
array (
'taxonomy' => 'recipe-category',
'field' => 'slug', // term_id, slug or name
'terms' => 'this-weeks-recipes'
)
)
);
$posts_array = get_posts( $args );
foreach ($posts_array as $post) {
$options[] = array(
'#value' => $post->ID,
'#title' => $post->post_title,
);
}
break;
}
return $options;
}
Note: I wasn't able to access your website's admin area, through VPN/proxy from Asia or US regions. It only intermittently worked from UK region, but constantly showed connection timeout errors. For this reason, it doesn't seem like a geolocation issue and you can get in touch with your hosting's support team for a potential security or performance restrictions.
I hope this helps and please let me know how it goes.
regards,
Waqar
My issue is resolved now. Thank you!