Support

Account

Home Forums Backend Issues (wp-admin) ACF relationship field not being populated in admin with custom post type

Helping

ACF relationship field not being populated in admin with custom post type

  • I have an issue where a second relationship ACF metabox is not getting populated with the posts of another custom post type.

    i am using ACF in 2 different custom post types called “recipe” and “product”, i have create 2 relationship fields in the product post type which are called “related products” and “related recipes”

    related products allows the selection of other products, and related recipes allows selections of recipes related to the product.

    in the recipe custom post type i have another acf relationship that is called “Related products” and again, this allows selection of the products custom post type that is related to the current recipe.

    recipes also have custom taxonomies.

    I have tried everything i can think of, removing custom taxonomies, deleting the ACF field and recreating it, mapping the 2 custom post types the same, testing the relationship field in the recipes post type.

    To me it looks like you cannot have 2 different ACF relationship metaboxes in the same post.

    the product post type is created like so

    /* create product custom post */
    /*****************************/
    
     function my_custom_product_posttype() {
    	$labels = array(
    		'name'               => _x( 'Product', 'post type general name' ),
    		'singular_name'      => _x( 'Product', 'post type singular name' ),
    		'add_new'            => _x( 'Add New', 'Product' ),
    		'add_new_item'       => __( 'Add New Product' ),
    		'edit_item'          => __( 'Edit Product' ),
    		'new_item'           => __( 'New Product' ),
    		'all_items'          => __( 'All Products' ),
    		'view_item'          => __( 'View Product' ),
    		'search_items'       => __( 'Search Products' ),
    		'not_found'          => __( 'No Products found' ),
    		'not_found_in_trash' => __( 'No Products found in the Trash' ), 
    		'parent_item_colon'  => '',
    		 'has_archive' => true,
    		
    		'menu_name'          => 'Products'
    	);
    	$args = array(
    		'labels'        => $labels,
    		'description'   => 'Holds our Products specific data',
    		'public'        => true,
    		'exclude_from_search' => false,
    		'query_var' => true,
    		'menu_position' => 4,
    		'capability_type' => 'post',
    		 'publicly_queryable' => true,
    		'supports'      => array( 'title', 'editor', 'thumbnail'),
    		'taxonomies' => array('post_tag'),
    		'has_archive'   => true,
    		'hierarchical' => false,
    		
    		
    		
    	);
    	register_post_type( 'product', $args );	
    }
    add_action( 'init', 'my_custom_product_posttype' );
    
    function my_updated_product_messages( $messages ) {
    	global $post, $post_ID;
    	$messages['product'] = array(
    		0 => '', 
    		1 => sprintf( __('Product updated. <a href="%s">View Product</a>'), esc_url( get_permalink($post_ID) ) ),
    		2 => __('Custom field updated.'),
    		3 => __('Custom field deleted.'),
    		4 => __('Product updated.'),
    		5 => isset($_GET['revision']) ? sprintf( __('Product restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
    		6 => sprintf( __('Product published. <a href="%s">View Product</a>'), esc_url( get_permalink($post_ID) ) ),
    		7 => __('Product saved.'),
    		8 => sprintf( __('Product submitted. <a target="_blank" href="%s">Preview Product</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
    		9 => sprintf( __('Product scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Product</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
    		10 => sprintf( __('Product draft updated. <a target="_blank" href="%s">Preview Product</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
    	);
    	return $messages;
    }
    add_filter( 'post_updated_messages', 'my_updated_product_messages' );
    
    /* end product custom post */
    /*****************************/

    and the recipe post type is created like so.

    /* create recipies custom post */
    /*****************************/
    
     function my_custom_recipe_posttype() {
    	$labels = array(
    		'name'               => _x( 'Recipe', 'post type general name' ),
    		'singular_name'      => _x( 'Recipe', 'post type singular name' ),
    		'add_new'            => _x( 'Add New', 'Recipe' ),
    		'add_new_item'       => __( 'Add New Recipe' ),
    		'edit_item'          => __( 'Edit Recipe' ),
    		'new_item'           => __( 'New Recipe' ),
    		'all_items'          => __( 'All Recipes' ),
    		'view_item'          => __( 'View Recipe' ),
    		'search_items'       => __( 'Search Recipes' ),
    		'not_found'          => __( 'No Recipes found' ),
    		'not_found_in_trash' => __( 'No Recipes found in the Trash' ), 
    		'parent_item_colon'  => '',
    		 'has_archive' => true,
    		
    		'menu_name'          => 'Recipes'
    	);
    	$args = array(
    		'labels'        => $labels,
    		'description'   => 'Holds our Recipe specific data',
    		'public'        => true,
    		'exclude_from_search' => false,
    		'query_var' => true,
    		'menu_position' => 4,
    		'capability_type' => 'post',
    		 'publicly_queryable' => true,
    		'supports'      => array( 'title', 'editor', 'thumbnail'),
    		'taxonomies' => array('post_tag'),
    		'has_archive'   => true,
    		'hierarchical' => false,
    		
    		
    		
    	);
    	register_post_type( 'recipe', $args );	
    }
    add_action( 'init', 'my_custom_recipe_posttype' );
    
    function my_updated_recipe_messages( $messages ) {
    	global $post, $post_ID;
    	$messages['recipe'] = array(
    		0 => '', 
    		1 => sprintf( __('Recipe updated. <a href="%s">View Recipe</a>'), esc_url( get_permalink($post_ID) ) ),
    		2 => __('Custom field updated.'),
    		3 => __('Custom field deleted.'),
    		4 => __('Product updated.'),
    		5 => isset($_GET['revision']) ? sprintf( __('Recipe restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
    		6 => sprintf( __('Recipe published. <a href="%s">View Recipe</a>'), esc_url( get_permalink($post_ID) ) ),
    		7 => __('Recipe saved.'),
    		8 => sprintf( __('Recipe submitted. <a target="_blank" href="%s">Preview Recipe</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
    		9 => sprintf( __('Recipe scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Recipe</a>'), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ),
    		10 => sprintf( __('Recipe draft updated. <a target="_blank" href="%s">Preview Recipe</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ),
    	);
    	return $messages;
    }
    add_filter( 'post_updated_messages', 'my_updated_recipe_messages' );
    
    /* end recipies custom post */
    /*****************************/

    the recipe post type uses 3 custom taxonomies, which are created like so.

    $labelsIngredients = array(
    		'name'                       => _x( 'Ingredients', 'taxonomy general name' ),
    		'singular_name'              => _x( 'Ingredients', 'taxonomy singular name' ),
    		'search_items'               => __( 'Search Ingredients' ),
    		'popular_items'              => __( 'Popular Ingredients' ),
    		'all_items'                  => __( 'All Ingredients' ),
    		'parent_item'                => null,
    		'parent_item_colon'          => null,
    		'edit_item'                  => __( 'Edit Ingredients' ),
    		'update_item'                => __( 'Update Ingredients' ),
    		'add_new_item'               => __( 'Add New Ingredients' ),
    		'new_item_name'              => __( 'New Ingredients Name' ),
    		'separate_items_with_commas' => __( 'Separate Ingredients with commas' ),
    		'add_or_remove_items'        => __( 'Add or remove Ingredients' ),
    		'choose_from_most_used'      => __( 'Choose from the most used Ingredients' ),
    		'not_found'                  => __( 'No Ingredients found.' ),
    		'menu_name'                  => __( 'Ingredients' ),
    	);
    
    	$argsIngredients = array(
    		'hierarchical'          => false,
    		'labels'                => $labelsIngredients,
    		'show_ui'               => true,
    		'show_admin_column'     => true,
    		'update_count_callback' => '_update_post_term_count',
    		'query_var'             => true,
    		'rewrite'               => array( 'slug' => 'ingredients' ),
    	);
    
    	register_taxonomy( 'ingredients', 'recipe', $argsIngredients );
    	
    /************* end ingredients taxonomy ************/
  • This is an old post, but I came across exactly the same problem with ACF 4.4.0. I have two relationship fields assigned to my normal WP posts.

    One of the relationship fields displays a list of all WP posts and has no taxonomy restrictions. The posts appear as expected in the relationship selection area.

    The other relationship field is supposed to display a list of custom post types restricted by a custom taxonomy. Nothing appears in this relationship selection area; it’s completely blank. The field itself appears, but the left pane is empty. Removing the taxonomy restriction did not fix the problem – the only way I could get anything to appear in the left pane was to choose either WP posts or WP pages as the post type.

    This appears to be a bug, but considering the lack of similar reports (I have been unable to find much online), maybe it’s a unique situation.

    I upgraded to 5.0 and that fixed the problem – kind of. The left pane correctly populates with the custom post type, but the search feature does not work. Regardless of what I enter, I get “no matches found”. I describe this problem in this related ticket:

    http://support.advancedcustomfields.com/forums/topic/search-not-working-on-relationship-field-in-wordpress-4-0/#post-22436

    So, upgrading to ACF 5.0 fixes the issue of the field not being populated, but now search does not work with custom post types.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘ACF relationship field not being populated in admin with custom post type’ is closed to new replies.