Is it possible to create custom field options with information included in a custom post type?
E.g., if I want to ask people what country they come from, can I include a select box (or even check/radio boxes) that uses values from CPT "Countries" or do I need to enter the values manually?
I need the select box to appear in amongst other fields for this group and not just as a last option contained in a field called Relationship at the base of the page, there are currently no options to select from the post types when adding a select field only adding manual or conditional.
Help appreciated as this task is so simple in ACF,
Yes you can populate such options in a SELECT field. Please consider followings sample code:
function my_wpt_field_options( $options, $title, $type )
{
switch( $title )
{
case 'a name of select field':
$options[] = array(
'#value' => 'xxx',
'#title' => 'dynamic add some option',
);
break;
case 'a name of radio option':
$options[] = array (
'#value' => 'xxx',
'#title' => 'dynamic added radio',
'#validate' => array (),
'#after' => '',
);
break;
}
return $options;
}
add_filter('wpt_field_options', 'my_wpt_field_options', 10, 3);
The above code demonstrates the case of SELECT and Radio fields. You can remove the other part (i.e. radio field). While in the SELECT field section you should use WordPress code to get titles of your posts, so you can populate required options. Please see https://codex.wordpress.org/Template_Tags/get_posts
You need to add this code in your theme's functions.php file to make it work.