danial dezfooli
danial dezfooli

Reputation: 818

Advanced custom fields on two post type - wordpress

I need to add fields with php in two pages (in advanced custom fields plugin , wordpress)

Here is my try :

acf_add_local_field_group(array (
    'key' => 'songs_options',
    'title'      => 'songs options',
    'fields' => array (
        array (
            'key' => 'field_1',
            'label' => 'test title',
            'name' => 'test_field',
            'type' => 'text',
        ),
    ),
    'location' => array (
        array (
            array (
                'param' => 'post_type',
                'operator' => 'IN', 
                'value' => array( 'songs', 'videos'),  // i need a code like this line
            ),
        )
    ),
));

Upvotes: 1

Views: 1461

Answers (1)

You should use the == operator with the locations, and add every location as a different array under 'location':

register_field_group(array (
    'key'    => 'songs_options',
    'title'  => 'songs options',
    'fields' => array (
        array (
            'key'   => 'field_1',
            'label' => 'test title',
            'name'  => 'test_field',
            'type'  => 'text',
        ),
    ),
    'location' => array (
        array (
            array (
                'param'    => 'post_type',
                'operator' => '==', 
                'value'    => 'songs',
            ),
        ),
        array (
            array (
                'param'    => 'post_type',
                'operator' => '==', 
                'value'    => 'videos',
            ),
        ),
    ),
));

Upvotes: 2

Related Questions