Hi @marcopanichi,
To create a relationship between your “Driver” and “Auto” custom post types, allowing you to select a car when creating or editing a driver post, you would typically need to do some custom coding.
Hope this information will help.
Regards!
I solved, client side, using jQuery.
This is the structure of the code I used, I hope it helps someone:
add_action('wp_footer', 'my_custom_select');
function my_custom_select()
{
$posts = new WP_Query(array(
...
));
$options = '';
if( $posts->have_posts() )
{
while( $posts->have_posts() )
{
$posts->the_post();
$options .= "field.append($('<option>').attr('value', '".get_the_ID()."').text(\"".get_the_title()."\"))\r\n";
}
}
wp_reset_postdata();
echo "<script type='text/javascript'>
jQuery(document).ready(function($) {
var field = $('#my_custom_select');
field.empty();
field.append($('<option>').attr('value', '-1').text(\"- select -\"))
$options
});
</script>";
}
}
Hi @marcopanichi,
That’s great to hear that you were able to solve the issue on the client side using jQuery! Sharing the code structure can be incredibly helpful for others who might encounter a similar problem. Thank you for being considerate and sharing your solution – it’s a fantastic way to contribute to the community and help others learn and grow.