I had a Custom post Relation - Post A is Parent and Post X is Child
Post A (parent) has a custom field - "due date".
I have a CRED form to create Post X and I want to select only from the parent posts that meet a condition, respectively Post A with a "due date" greater than today.
You will need some code to modify which parent posts are displayed in the selector on the form to publish child posts.
The code will need to use the WordPress pre_get_posts hook to modify the query arguments, meaning that the normal WP_Query parameters are available. (See the WordPress documentation for the full list of parameters: https://developer.wordpress.org/reference/classes/wp_query/#parameters).
Here is a simple example of the kind of code you need to intervene in the correct place, which you can modify for your needs for the date field:
/**
* Intercept the query to populate the select dropdown to choose parent post in form to publish child post
* Modify the query as required
*/
add_action( 'wp_ajax_select2_potential_relationship_parents', 'ts_mod_parent_selector', 1 );
// if guest users can use your relationship form then uncomment the following line
// add_action( 'wp_ajax_nopriv_select2_potential_relationship_parents', 'ts_mod_parent_selector', 1 );
function ts_mod_parent_selector(){
add_action( 'pre_get_posts', 'ts_pre_get_posts_for_parent_selector' );
function ts_pre_get_posts_for_parent_selector( $query ){
// example: limit parents to those with Types custom field "active" = 1
// note that Types custom fields use a 'wpcf-' meta key prefix
$query->set( 'meta_key', 'wpcf-active' );
$query->set( 'meta_value', '1' );
$query->set( 'compare', '=' );
}
}