-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.php
70 lines (57 loc) · 1.66 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<?php
// functions.php
/**
* ACF rule constant - hides all default fields except permalink and title
*/
use ACF\ACFGroup;
use ACF\ACFLocations;
$ACF_HIDE_ALL = [
'the_content',
'excerpt',
'custom_fields',
'discussion',
'comments',
'revisions',
'author',
'format',
'categories',
'tags',
'send-trackbacks'
];
/*
* Option page fields
*/
acf_add_options_page();
acf_add_options_sub_page('Pages');
acf_add_options_sub_page('Settings');
/**
* Location rules
*/
$optionPageTheme = [
ACFLocations::optionPage('theme')
];
$optionPageSettings = [
ACFLocations::optionPage('settings')
];
/**
* Option page groups and fields example
*
* Groups and fields will be rendered on the page in order you first registered the group/field
*
* Field order can be updated by just reordering group methods, groups might not update
*/
$opThemeGroup = new ACFGroup('theme_settings_group', 'Label', $optionPageTheme);
$opThemeGroup->addPostObject('op_theme_contact_page', 'Select contact page');
$opThemeGroup->addMessage('op_theme_msg', 'Some message example');
$opThemeGroup->addTextField('op_theme_text_field', 'Some text field', [
'default_value' => 'default_calue',
'width' => 50
]);
/**
* Template groups and fields example
*/
$pageBackground = new ACFGroup('od_page_background', 'Page background image', [[ACFLocations::template('contact_form_template')]]);
$pageBackground->addImageField('page_background_image', 'Background image');
// your template file
get_field('op_theme_contact_page', 'options'); // Returns id of chosen post
get_field('page_background_image'); // Returns image id if current query loop item has that field