Custom fields that are not displayed in a personalized post type message

I have a custom post type called Designer. Each column will use different unique advanced custom fields, as each column has unique patterns. Using the code below, I can give the rules for each message in the publication type Designer and save, but custom fields do not appear on pages after editing on the backend. Usually this code should ork, but I don't know what happened to the code

Please, help.

add_filter('acf/location/rule_types', 'acf_location_rules_types'); function acf_location_rules_types( $choices ) { $choices['Custom Post types']['cpt_parent'] = 'Custom post type parent'; return $choices; } add_filter('acf/location/rule_values/cpt_parent', 'acf_location_rules_values_cpt_parent'); function acf_location_rules_values_cpt_parent( $choices ) { $args = array( 'hierarchical' => true, '_builtin' => false ); $posttypes = get_post_types( $args ); if( $posttypes ) { foreach( $posttypes as $posttype ): if( $posttype != 'acf' ): $args = array( 'post_type' => 'designer', 'posts_per_page' => -1, 'post_status' => 'publish' ); $customposts = get_posts( $args ); if ( $customposts ) { foreach( $customposts as $custompost ){ $choices[ $custompost->ID] = $custompost->post_title; } } endif; endforeach; } return $choices; } //MATCH THE RULE add_filter('acf/location/rule_match/cpt_parent', 'acf_location_rules_match_cpt_parent', 10, 3); function acf_location_rules_match_cpt_parent( $match, $rule, $options ) { global $post; $selected_post = (int) $rule['value']; // post parent $post_parent = $post->post_parent; if( $options['page_parent'] ) { $post_parent = $options['page_parent']; } if ($rule['operator'] == "=="){ $match = ( $post_parent == $selected_post ); } elseif ($rule['operator'] != "!="){ $match = ( $post_parent != $selected_post ); } return $match; } 

enter image description here

+5
source share
2 answers

The "Your Artist Collection" field group is configured for only one post, the Post 1 post-constructor, which is the publication type of the constructor.

I don’t understand why all the code is needed? Simply create a different field group for each message, which requires a separate field group and a separate rule for each.

Ok, sorry, I understand the problem now, and I recreated the problem with a local installation.

In the line of code below you are looking for post_parent, but I think you should look for the identifier.

I changed this:

 $post_parent = $post->post_parent; 

:

 $post_parent = $post->ID; 

and it works for me.

+7
source

If I understand your problem correctly, on the wp-admin message editing page, click on the screen settings in the upper right corner. In the menu that appears, make sure that user fields are selected. This will result in custom editable fields.

-1
source

Source: https://habr.com/ru/post/1266004/


All Articles