Skip Navigation

[Resolved] Dynamic population of select: only 5 options are loaded

This thread is resolved. Here is a description of the problem and solution.

Problem:

I created 2 custom fields of type "Select" in this post type.
Options of these 2 select fields must be the titles (text) and postid (value) of all available projects.

BUT the select fields each show only 5 options, while there are 8 published projects.

Solution:

Please try to add Pagination limitation parameter in $args, for example:

https://toolset.com/forums/topic/dynamic-population-of-select-only-5-options-are-loaded/#post-1762209

Relevant Documentation:

https://developer.wordpress.org/reference/classes/wp_query/#pagination-parameters

This support ticket is created 3 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 2 replies, has 2 voices.

Last updated by peterV-10 3 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1762155
toolset-select-problem.jpg

I have a new post type "Project".
I created 2 custom fields of type "Select" in this post type.
Options of these 2 select fields must be the titles (text) and postid (value) of all available projects.
Reason: I use these dropdowns to select "Other relevant projects".

For this, I created a filter in functions.php:
// ----------------------------------
//dynamically populate select field from Types
add_filter( 'wpt_field_options', 'prefix_custom_options', 10, 3);
function prefix_custom_options( $options, $title, $type ){
switch( $title ){
case 'Gerelateerd Project 1':
$options = array();
$args = array(
'post_type' => 'project',
'post_status' => 'publish');

$options[] = array(
'#value' => 0,
'#title' => 'Kies een project...',
);

$posts_array = get_posts( $args );
foreach ($posts_array as $post) {
$options[] = array(
'#value' => $post->ID,
'#title' => $post->post_title,
);
}
break;
case 'Gerelateerd Project 2':
$options = array();
$args = array(
'post_type' => 'project',
'post_status' => 'publish');

$options[] = array(
'#value' => 0,
'#title' => 'Kies een project...',
);

$posts_array = get_posts( $args );
foreach ($posts_array as $post) {
$options[] = array(
'#value' => $post->ID,
'#title' => $post->post_title,
);
}
break;
}
return $options;
}
// ----------------------------------

This works, BUT the select fields each show only 5 options, while there are 8 published projects.
More in detail: only the 5 youngest are shown. When I create a new test project, this is added in the options list, and the oldest one disappears.

My question: is there a limit of 5 I am not aware of? Is there something else I'm doing wrong?
Thank you!

#1762209

Hello,

Please try to add Pagination limitation parameter in $args, for example:

$args = array(
'post_type' => 'project',
'post_status' => 'publish',
'posts_per_page'=>-1
);

And test again

#1762223

My issue is resolved now. Thank you very much!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.