Support

Account

Home Forums Backend Issues (wp-admin) Particular Custom Post Type Rules for a group of fields

Solved

Particular Custom Post Type Rules for a group of fields

  • Hi !

    First of all, thank you very much for your great plugin ! We use it every day here and we’ve persuaded a lot of people to use it too 😉 !

    Here is my question/need :

    When I create a group of fields, I can specify rules. For example, I want my group of field to be available only for a page or a post or a custom post type. I can also make a group of fields available for a particular page or a particular post simply by specifying the post title.

    What I’d like is to make a group of files available for a particular custom post type. Let’s say I have a custom post type called “Events” with multiple events. For one of these event, I’d like to have special group of fields.

    How could I do that ? I can’t specify my custom post type in the first field of the rules maker…

    Thanks a lot,
    Cédric

  • Hi @cedric_charles

    All post types will be available in the location rules dropdown., even if the post_type public setting is false.

    If your post_type is not appearing, then perhaps your post_type is not registered when ACF does the AJAX request to populate the select field.

    This would be the case if you have wrapped your register code within an action. During an AJAX call, no WP action will be called (for example: admin_menu, admin_head, plugins_loaded, etc)

    Could this be the issue?

    Can you try setting the post_type to ‘post’ and then saving the field group. Does the newly refreshed page contain the correct post_types in the dropdown?

  • Hi Elliot and thank you for you response.

    Here is how I vahe registered my CPT :

    function custom_post_type2() {
    
    	$labels = array(
    		'name'                => _x( 'Products', 'Post Type General Name', 'twentythirteen' ),
    		'singular_name'       => _x( 'Product', 'Post Type Singular Name', 'twentythirteen' ),
    		'menu_name'           => __( 'Products', 'twentythirteen' ),
    		'parent_item_colon'   => __( 'Parent Product:', 'twentythirteen' ),
    		'all_items'           => __( 'All Products', 'twentythirteen' ),
    		'view_item'           => __( 'View Product', 'twentythirteen' ),
    		'add_new_item'        => __( 'Add New Product', 'twentythirteen' ),
    		'add_new'             => __( 'New Product', 'twentythirteen' ),
    		'edit_item'           => __( 'Edit Product', 'twentythirteen' ),
    		'update_item'         => __( 'Update Product', 'twentythirteen' ),
    		'search_items'        => __( 'Search Products', 'twentythirteen' ),
    		'not_found'           => __( 'No Products found', 'twentythirteen' ),
    		'not_found_in_trash'  => __( 'No Products found in Trash', 'twentythirteen' )
    	);
    	$args = array(
    		'label'               => __( 'product', 'twentythirteen' ),
    		'description'         => __( 'Product Page', 'twentythirteen' ),
    		'labels'              => $labels,
    		'supports'            => array( 'title', 'editor', 'excerpt', 'thumbnail', ),
    		'hierarchical'        => false,
    		'public'              => true,
    		'show_ui'             => true,
    		'show_in_menu'        => true,
    		'show_in_nav_menus'   => true,
    		'show_in_admin_bar'   => true,
    		'menu_position'       => 5,
    		'can_export'          => true,
    		'has_archive'         => true,
    		'exclude_from_search' => false,
    		'publicly_queryable'  => true,
    		'capability_type'     => 'page',
        'rewrite'            	=> array( 'slug' => 'nos-produits' ),
    	);
    	register_post_type( 'product', $args );
    
    }
    
    // Hook into the 'init' action
    add_action( 'init', 'custom_post_type2', 0 );

    In the attached file, you can see what I have. I want to have my custom post type in field 1. and the the different title of my create post in field 2.

    After doing what you say, I still have only what you can see in the attached file in the field 1.

    Thanks a lot for your help.

  • Hi @cedric_charles

    Just to confirm the issue is with the ‘post’ location rule, not the ‘post_type’ location rule?

    I’ll add your code to my install and test that the post’s show in the location rule values.

    Thanks
    E

  • Hi @cedric_charles

    I found it!
    Because your post type has a ‘capability_type’ => ‘page’, the posts will show up under ‘page’, not ‘post’!

    Thanks
    E

  • Hi Elliot !

    Nice, you’re right it works 🙂 !

    Any possibilities that in the future, you could add a section for each post type in the first field ? As we have

    
    Posts
    Category
    

    We could directly have

    
    My first Custom post type
    My Custom taxonomy
    

    Instead of have them in the second field ?

  • Hi @cedric_charles

    Thanks for the feature request. I’ll have a think about this one.

    Cheers
    E

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

The topic ‘Particular Custom Post Type Rules for a group of fields’ is closed to new replies.