Navigation überspringen

[Gelöst] Child post form: Selecting parent post who meets specific parent field condition

This support ticket is created vor 10 months, 2 weeks. 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Zeitzone des Unterstützers: Asia/Kolkata (GMT+05:30)

Dieses Thema enthält 1 reply, hat 1 Stimme.

Zuletzt aktualisiert von Robert Mueller vor 10 months, 2 weeks.

Assistiert von: Minesh.

Author
Artikel
#2817743

I am programming a Toolset child post form in which the user shall also select the parent post of an 1:n relationship. However, due to the context only parent posts fullfulling a specific field condition (e.g. type ="C") shall be visible / selectable. The conditional group offered in the GUI only allows conditions on child fields, not on parent fields when selecting the parent post. Is there any possibility for example in the expert mode to insert some condition for the parent to show up in the selection list when setting the parent post?

Any hint would be great.
Robert

#2817882

Minesh
Unterstützer

Sprachen: Englisch (English )

Zeitzone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As I understand - on a child post form where you have parent post select field using which you can assign the parent post, you want to display only parent post where parent post custom field type value is equal to "C". is that correct? if yes:

Can you please try to add the following code to "Custom Code" section offered by Toolset:
=> https://toolset.com/documentation/programmer-reference/adding-custom-code/using-toolset-to-add-custom-code/#adding-custom-php-code-using-toolset

Alternatively - you can also add the following code to your current theme's functions.php file:

function func_filter_parent_dropdown_posts_with_custom_field_value($query){
    global $post;
    
 
    if (defined('DOING_AJAX') && DOING_AJAX and isset($_REQUEST['action']) and isset($_REQUEST['slug']) and isset($_REQUEST['form_type'])    ) { 
     
        $parent_post_type = 'myparent_posttype';  /// replace with your parrent post type slug
        $relationship_slug = 'relationship-slug'; ///replace with your post-relationship slug
         
      
       if($_REQUEST['action']=='select2_potential_relationship_parents' and $_REQUEST['slug']==$relationship_slug){
              
            if($query->query['post_type'][0]==$parent_post_type ){
                $meta_query = array(   array(
                                     'key' => 'wpcf-types',
                                     'value' => 'C',
                                     'type' => 'CHAR',
                                    'compare'=> '=' )
                                );
                $query->set( 'meta_query', $meta_query );
                 
                 
            }
        }       
    }
}
add_action( 'pre_get_posts', 'func_filter_parent_dropdown_posts_with_custom_field_value', 101, 1 );

Can you please try to use the above code and check if that help you to resolve your issue.

#2818457

Thank you very much.