Support

Account

Home Forums General Issues Same Relationship field for multiple Post Options sub-pages?

Solved

Same Relationship field for multiple Post Options sub-pages?

  • How can I ensure that the data saved by a Relationship field when on an Options page for a Post type is separate?

    Detail below:

    I have an ACF field group, “Features”, containing a Relationship field.

    It is intended to allow me to pre-set some featured posts for a couple of custom post types – “Reports” and “Articles”.

    For those post types, I have created an Options sub-page like this…

    // Support showcase Features for this post type, via ACF
    
    if( function_exists('acf_add_options_page') ) {
    
    	// add sub page
    	acf_add_options_sub_page(array(
    		'page_title' 	=> 'Articles Features',
    		'menu_title' 	=> 'Articles Features',
        'menu_slug'   => 'articles-features',
        'capability'  => 'edit_posts',
    		'parent_slug' 	=> 'edit.php?post_type=article',
        'position'    => false,
        'icon_url'    => false
    	));
    
    }
    

    The same goes for “Reports”.

    And then I apply the “Features” field group to both Options sub-pages – “Articles Features” and “Reports Features”.

    The problem is… the data is the same.
    That is, the six Relationship posts set for “Reports Features” also show up in the Options sub-page for “Articles Features”.

    How can I ensure that these two things are separate, so that I can save the features distinctly per post type, without recreating the field group?

    Thanks.

  • As @hube2 points out in the other linked thread, the method to use is…

    In the acf_add_options_sub_page declaration, add 'post_id' => 'article' as a parameter.

    This is how the field data, as entered on the Options page corresponding to my post type, will be saved.

    On the display end, display using $featured_posts = get_field('featured_posts', 'article');

    ‘article’ and ‘report’ are both used.

    In my case, at the display end, I use $queried_object->name to dynamically infer either ‘article’ or ‘report’ post types.

    Thanks.

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

The topic ‘Same Relationship field for multiple Post Options sub-pages?’ is closed to new replies.