php 使用ACF选项页面的WP全局自定义字段

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 使用ACF选项页面的WP全局自定义字段相关的知识,希望对你有一定的参考价值。

<?php 

$field_array = array(
    'global_facebook',
    'global_twitter',
    'global_instagram'
);

foreach ($field_array as $custom_field) {
    $$custom_field = get_field($custom_field, 'option');
}
<?php 

/**
 * ACF Options Page
 */ 
if ( function_exists('acf_add_options_page') ) {
  
  $args = array(
    
  	/* (string) The title displayed on the options page. Required. */
  	'page_title' => 'Options',
  	
  	/* (string) The title displayed in the wp-admin sidebar. Defaults to page_title */
  	'menu_title' => '',
  	
  	/* (string) The URL slug used to uniquely identify this options page. 
  	Defaults to a url friendly version of menu_title */
  	'menu_slug' => '',
  	
  	/* (string) The capability required for this menu to be displayed to the user. Defaults to edit_posts.
  	Read more about capability here: http://codex.wordpress.org/Roles_and_Capabilities */
  	'capability' => 'edit_posts',
  	
  	/* (int|string) The position in the menu order this menu should appear. 
  	WARNING: if two menu items use the same position attribute, one of the items may be overwritten so that only one item displays!
  	Risk of conflict can be reduced by using decimal instead of integer values, e.g. '63.3' instead of 63 (must use quotes).
  	Defaults to bottom of utility menu items */
  	'position' => false,
  	
  	/* (string) The slug of another WP admin page. if set, this will become a child page. */
  	'parent_slug' => '',
  	
  	/* (string) The icon class for this menu. Defaults to default WordPress gear.
  	Read more about dashicons here: https://developer.wordpress.org/resource/dashicons/ */
  	'icon_url' => false,
  	
  	/* (boolean) If set to true, this options page will redirect to the first child page (if a child page exists). 
  	If set to false, this parent page will appear alongside any child pages. Defaults to true */
  	'redirect' => true,
  	
  	/* (int|string) The '$post_id' to save/load data to/from. Can be set to a numeric post ID (123), or a string ('user_2'). 
  	Defaults to 'options'. Added in v5.2.7 */
  	'post_id' => 'options',
  	
  	/* (boolean)  Whether to load the option (values saved from this options page) when WordPress starts up. 
  	Defaults to false. Added in v5.2.8. */
  	'autoload' => false,
  	
  	/* (string) The update button text. Added in v5.3.7. */
  	'update_button'		=> __('Update', 'acf'),
  	
  	/* (string) The message shown above the form on submit. Added in v5.6.0. */
  	'updated_message'	=> __("Options Updated", 'acf'),
  			
  );

	acf_add_options_page($args);
	acf_add_options_sub_page('Social Media');

}

以上是关于php 使用ACF选项页面的WP全局自定义字段的主要内容,如果未能解决你的问题,请参考以下文章

php 适用于wp-admin的ACF自定义选项菜单

Wordpress ACF 字段如何从自定义帖子类型中获取选项

查询ACF在自定义分类模板中的WP_Query期间发布对象

在自定义分类模板中的 WP_Query 期间查询(2)ACF 发布对象

php ACF Pro |自定义选项页面

php 使用自定义post_id为ACF选项页面设置正确的语言