WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Custom Fields
Show field in backend only on certain posts (1 post)

  1. Mark Jansen
    Member
    Posted 6 months ago #

    Hello,

    I can't really find this option, perhaps it does not exist or I may be doing it wrong, but I am hoping someone can help me out.

    I want a custom field only to show on a a child page. So I have this in my custom plugin code:

    if(function_exists("register_field_group")) {
    			register_field_group(array (
    				'id' => 'acf_webinar',
    				'title' => 'Webinar',
    				'fields' => array (
    					array (
    						'key' => 'field_525fffb950527',
    						'label' => 'Webinar code',
    						'name' => 'webinar_code',
    						'type' => 'text',
    						'default_value' => '',
    						'placeholder' => '',
    						'prepend' => '',
    						'append' => '',
    						'formatting' => 'html',
    						'maxlength' => '',
    					),
    				),
    				'location' => array (
    					array (
    						array (
    							'param' => 'post_type',
    							'operator' => '==',
    							'value' => 'course',
    							'order_no' => 0,
    							'group_no' => 0,
    						),
    						array (
    							'param' => 'page_type',
    							'operator' => '==',
    							'value' => 'child',
    							'order_no' => 1,
    							'group_no' => 0,
    						),
    						array (
    							'param' => 'post_parent',
    							'operator' => '==',
    							'value' => $this->options['webinar_parent'],
    							'order_no' => 2,
    							'group_no' => 0,
    						),
    					),
    				),
    				'options' => array (
    					'position' => 'side',
    					'layout' => 'default',
    					'hide_on_screen' => array (
    					),
    				),
    				'menu_order' => 0,
    			));
    		}

    But some how the post_parent option doesn't seem to be working. The variable $this->options['webinar_parent'] contains the right value, but even if I replace it with a hardcoded post ID it's still not working.

    I can't really find this in the documentation, but I'm hoping some one over here can help me out. I want this field only to show if the post is a child of the webinar parent.

    Regards,

    Mark

    http://wordpress.org/plugins/advanced-custom-fields/

Reply

You must log in to post.

About this Plugin

About this Topic