advanced-custom-fields 相关问题

高级自定义字段是一个免费的WordPress插件,充当自定义字段的GUI层。自定义字段是WP的原生字段,显示在页面,帖子和自定义帖子类型上,但本机自定义字段界面不是非常用户友好。 ACF使用字段组附加字段以编辑屏幕。

高级自定义字段从转发器中删除行

我有一个大约有 270 行的中继器,我想使用“delete_row()”按索引删除特定的行,我可以很容易地做到这一点,但是有 270 行,这个函数似乎真的很...

回答 0 投票 0

使用 Ajax 更新 Wordpress 管理中的 ACF 字段

我有一个问题,我已经尝试解决了一段时间了。在我看来,这项任务与那些使用 ACF 并希望将字段从一篇文章替换到另一篇文章的人相关。有人马...

回答 0 投票 0

按作者指定的顺序对 ACF 关系字段进行排序

我希望实现与本文所述相同的功能:https://support.advancedcustomfields.com/forums/topic/order-by-sorting-in-relationship-field/ 如上链接所示,我是

回答 1 投票 0

如果选择了一个组,如何创建元素或小部件以获取特定位置的所有组?

如何获取特定位置的所有 ACF 组,然后如果选择了一个组,则使用 AJAX 和 jQuery 获取其字段? 任何人都请帮助我,我将非常感激 如何获取特定位置的所有 ACF 组,然后如果选择了一个组,则使用 AJAX 和 jQuery 获取其字段? 任何人请帮助我,我将非常感激 <?php if ( !defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly. } class Elementor_List_Widget extends\ Elementor\ Widget_Base { public function get_name() { return 'elementor-acf-fields'; } public function get_title() { return __( 'acf groups and fields', 'elementor-acf-fields' ); } public function get_icon() { return 'eicon-editor-code'; } public function get_categories() { return [ 'General' ]; } protected function _register_controls() { $all_groups = get_groups(); $get_fields = get_acf_fields(); $this->start_controls_section( 'section_acf_fields', [ 'label' => __( 'ACF Fields', 'elementor-acf-fields' ), ] ); $this->add_control( 'acf_groups', [ 'label' => __( 'ACF Groups', 'elementor-acf-fields' ), 'type' => \Elementor\ Controls_Manager::SELECT, 'groups' => $all_groups, 'default' => '', 'label_block' => true, 'ajax' => [ 'callback' => [ $this, 'get_acf_fields' ], 'event' => 'change', ], ] ); $this->add_control( 'acf_fields', [ 'label' => __( 'ACF Fields', 'elementor-acf-fields' ), 'type' => \Elementor\ Controls_Manager::SELECT, 'options' => $second_variable, 'default' => '', 'label_block' => true, ] ); $this->end_controls_section(); } public function get_acf_fields( $request ) { $group_id = $request[ 'group_id' ]; $fields = []; if ( function_exists( 'acf_get_fields' ) ) { $acf_fields = acf_get_fields( $group_id ); if ( $acf_fields ) { foreach ( $acf_fields as $field ) { $fields[ $field[ 'key' ] ] = $field[ 'label' ]; } } } return [ 'options' => $fields, ]; } public function get_groups() { if ( function_exists( 'acf_get_field_groups' ) ) { $acf_groups = \acf_get_field_groups(); } else { $acf_groups = \apply_filters( 'acf/get_field_groups', [] ); } $specifications_group_id = $acf_groups; // Post ID of the specifications field group. $specifications_fields = array(); $fields = acf_get_fields( $specifications_group_id ); foreach ( $fields as $field ) { $field_value = get_field( $field['name'] ); if ( $field_value && !empty( $field_value ) ) { $specifications_fields[$field['name']] = $field; $specifications_fields[$field['name']]['value'] = $field_value; } } return $specifications_fields; } protected function render() {} } 选择一个选项时,根据其自定义位置在下拉列表中获取所有 acf 组的答案,然后其字段将显示,请参见下面的代码。为此,我创建了名为“jpro_acf_group_select2”的自定义元素控件 <?php /** * Elementor currency control. * * A control for displaying a select field with the ability to choose currencies. * * @since 1.0.0 */ class Elementor_Jobpro_ACF_Group_Select2_Control extends \Elementor\Base_Data_Control { /** * Get currency control type. * * Retrieve the control type, in this case `currency`. * * @since 1.0.0 * @access public * @return string Control type. */ public function get_type() { return 'jpro_acf_group_select2'; } public function enqueue() { //wp_enqueue_script( 'select2', 'https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js', array( 'jquery' ), '4.0.13', true ); wp_register_script( 'elementor-group-scripts', get_plugin_url( '/assets/js/elementor-group-scripts.js'), [ 'jquery-elementor-select2' ], '1.0.0' ); //wp_register_script( 'elementor-group-scripts', get_plugin_url( '/assets/js/elementor-group-scripts.js'), [ 'select2' ], '1.0.0' ); wp_enqueue_script( 'elementor-group-scripts' ); $jobpro_plugin_arr = array( 'site_url' => home_url('/'), 'ajax_url' => home_url('/?jobpro_settings=1'), 'error_msg' => esc_html__('There is some problem.', 'jobpro-employement-verification'), ); wp_localize_script('elementor-group-scripts', 'jobpro_plugin_data', $jobpro_plugin_arr); } public function get_value( $control, $settings ) { if ( isset( $settings[ $control['name'] ] ) ) { $group_item = $settings[ $control['name'] ]; } else { $group_item = $control['default']; } return $group_item; } /** * Render currency control output in the editor. * * Used to generate the control HTML in the editor using Underscore JS * template. The variables for the class are available using `data` JS * object. * * @since 1.0.0 * @access public */ public function content_template() { $control_uid = $this->get_control_uid(); ?> <div class="elementor-control-input-wrapper"> <select id="<?php echo $control_uid; ?>" class="elementor-select2 jobpro-resume-group-select2 {{{ data.class }}}" type="select2"data-setting="{{ data.name }}"> <# var printOptions = function( options ) { _.each( options, function( option_title, option_value ) { #> <?php // If the option title is array of title & icon. ?> <option value="{{ option_value }}">{{{ option_title?.title || option_title }}}</option> <# } ); }; if ( data.groups ) { for ( var groupIndex in data.groups ) { var groupArgs = data.groups[ groupIndex ]; if ( groupArgs.options ) { #> <optgroup label="{{ groupArgs.label }}"> <# printOptions( groupArgs.options ) #> </optgroup> <# } else if ( _.isString( groupArgs ) ) { #> <option value="{{ groupIndex }}">{{{ groupArgs }}}</option> <# } } } else { printOptions( data.options ); } #> </select> </div> <# if ( data.description ) { #> <div class="elementor-control-field-description">{{{ data.description }}} </div> <# } #> <?php } } 下面是它的js和ajax // Wait for the Elementor editor to load jQuery(window).on('elementor:init', function () { // Add custom control JS to the widget edit mode elementor.hooks.addAction('panel/open_editor/widget', function (panel, model, view) { // Check if the current widget is our custom widget if (model.get('widgetType') === 'resume-listings') { jQuery('.jobpro-resume-group-select2').select2({ width: '100%', allowClear: true, placeholder :'Select Group', }); var widgetType = model.get( 'widgetType' ); var settings = model.get('settings'); var $element = jQuery('#elementor-panel-page-editor').find('.jobpro-group-key'); var settings_attributes = settings.attributes; var select_resume_group = settings.attributes.select_resume_group; if(select_resume_group == 'undefined'){ select_resume_group = jQuery('.jobpro-resume-group-select2').val(); } var $fields_element = jQuery('#elementor-panel-page-editor').find('.jobpro-acf-group-fields-select2'); if(select_resume_group){ if ( $element.length ) { $element.val(select_resume_group); } if ( $fields_element.length ) { $fields_element.data('group_item', select_resume_group); jobpro_resume_group_fields_(settings_attributes, $fields_element, select_resume_group); } } jQuery(document).on('change', '.jobpro-resume-group-select2',function (e) { select_resume_group = jQuery(this).val(); $element.val(select_resume_group); $fields_element.data('group_item', select_resume_group); $fields_element.val('').trigger('change'); jobpro_resume_group_fields_(settings_attributes, $fields_element, select_resume_group); }); function jobpro_resume_group_fields_(settings_attributes, $fields_element, select_resume_group){ jQuery.ajax({ type: "GET", dataType: "json", url: jobpro_plugin_data.site_url+'wp-json/wp/v1/jobpro-get-group-fields', data: { search: '', verification_group: select_resume_group, }, success: function(data) { if (data.status == 'success') { $fields_element.find('option:not(:first)').remove(); jQuery.each(data.results, function(index, option) { $fields_element.append(jQuery('<option>').text(option.text).attr('value', option.id)); }); $fields_element.each(function() { var currentElement = jQuery(this); let dropdownName = currentElement.attr('name'); if(dropdownName == 'undefined'){ dropdownName = currentElement.data('setting'); } dropdownName = currentElement.data('setting'); if(dropdownName !== 'undefined'){ var keyValue = settings_attributes[dropdownName]; currentElement.val(keyValue).trigger('change'); } }); } }, error: function(jqXHR, textStatus, errorThrown) { console.error(errorThrown); } }); } $fields_element.select2({ width: '100%', allowClear: true, placeholder :'Select Group Fields', //minimumInputLength: 3, tags: false, ajax: { data: function (params) { if ( select_resume_group.length < 1 || select_resume_group == 'undefined') { select_resume_group = jQuery('.jobpro-resume-group-select2').val(); } var query = { search: params.term, verification_group: select_resume_group } return query; }, url: jobpro_plugin_data.site_url+'wp-json/wp/v1/jobpro-get-group-fields', dataType: 'json', cache: true, } }); } }); }); 下面是ajax public function jobpro_load_group_fields(){ $search = !empty($_GET['search']) ? sanitize_text_field($_GET['search']) : ''; $verification_group = !empty($_GET['verification_group']) ? sanitize_text_field($_GET['verification_group']) : ''; $acf_group_object = get_field_object($verification_group); $verification_group_fields = !empty($acf_group_object['sub_fields']) ? $acf_group_object['sub_fields'] : ''; $responsedata = array(); $responsedata['status'] = 'success'; $responsedata['results'] = array(); foreach ($verification_group_fields as $field) { $name = isset($field['name']) ? $field['name'] : ''; $label = isset($field['label']) ? $field['label'] : ''; $responsedata['results'][] = array('id' => $name, 'text' => $label); } wp_send_json($responsedata); }

回答 1 投票 0

嘿!我们可以使用 JAVA 创建 Sci fi Advance UI 吗?我的意思是用java编程是可能的吗? [关闭]

我想使用 JAVA 编程创建一个高级用户界面,就像一个超级未来的界面,你可以认为它就像 2100 年或 2150 年的软件界面。谁能给我或建议我...

回答 0 投票 0

允许“客户”用户角色使用 acf_form 在前端上传文件

我在 woocommerce“查看订单”页面中使用 acf_form()(高级自定义字段前端表单)创建了一个前端表单,允许客户为我们上传一些文件,该表单适用于

回答 5 投票 0

使用 ACF Extended 显示多个文件

我在使用 ACF 文件字段类型在高级自定义字段扩展 P 上启用“允许多个文件”的 WordPress 帖子上显示多个文件(.pdf、.docx、.xlsx 等)时遇到问题...

回答 1 投票 0

在 WordPress 中更新页面后更改内容

我目前有一些工作 jQuery,每 3.5 秒重新加载一次内容。但是,我想知道是否有可能做到这一点,以便在 WordPress 中更新页面时,只有相关的

回答 0 投票 0

Woocommerce 保存 ACF 字段

我正在使用 Woocommerce、片段和 ACF 字段,我在产品中创建了元字段,我想在购物车项目中获取 ACF 字段,并将它们保存在订单表中但不起作用,我已经检查了巨大的

回答 0 投票 0

我使用 Advanced Custom Field Pro 插件创建了一些自定义字段,如何在我的 woocommerce 订单中显示这些字段?

我想在 Frontend 的顺序和 Backends 的顺序中看到。如果有一个插件解决方案对我来说更好 我使用了 php 代码,但我不知道出了什么问题。我不明白。我想用...

回答 0 投票 0

ACF 创建多字段,自定义字段类型

我已经按照本文档 https://www.advancedcustomfields.com/resources/creating-a-new-field-type/ 创建了自定义字段类型,我有以下字段: YouTube ID(输入类型文本) 提交 ...

回答 1 投票 0

ACF 自定义字段类型,'input_admin_enqueue_scripts' 回调函数未触发

我正在使用他们的模板,按照他们在此处推荐的方式创建我的自定义字段类型:https://www.advancedcustomfields.com/resources/creating-a-new-field-type/ 这是我的场景,我想...

回答 1 投票 0

在 Wordpress 中显示关系的高级自定义字段

我实际上需要在我的单个博客页面上检索关系的高级自定义字段。 这是我的查询: 我实际上需要在我的单个博客页面上检索关系的高级自定义字段。 这是我的查询: <?php $ingredients = get_field('ingredients'); if ($ingredients) { echo '<ul>'; foreach($ingredients as $ingredient) { ?> <li><?php echo get_the_title($ingredient); ?> </li> <? } echo '</ul>'; } ?> 我需要的ACF被命名为“quantite”。 我尝试了很多东西: <?php $ingredients = get_field('ingredients'); if ($ingredients) { echo '<ul>'; foreach($ingredients as $ingredient) { ?> <li><?php echo get_the_title($ingredient); echo get_field('quantite'); / echo the_field('quantite'); echo get_field($ingredient, 'quantite'); / echo the_field($ingredient, 'quantite');?> </li> <?php} echo '</ul>'; } ?> 没有任何效果。我尝试使用和不使用“回声”。 你有什么想法吗? 编辑:更具体地说,除了 ACF 之外,一切正常。例如 get_the_title($ingredient) 正在工作。我也尝试了缩略图,它有效。但与ACF无关。 谢谢

回答 0 投票 0

将 ACF url 作为重定向注入到 Hubspot 表单代码中

我正在使用 Divi、ACF 和 Hubspot。 我有一个 hubspot 表单,添加到 Divi 的代码模块中,可重定向到我客户站点上的门控内容。我希望客户能够改变 ...

回答 0 投票 0

如何在页面和自定义 postypes 中将所有 ACF 字段公开给 Wordpress REST API

我想将属于页面或自定义帖子类型的所有 ACF 字段公开给 WordPress REST API,以便通过 javascript 进行一些 API 调用。 最终的预期结果将是所有...

回答 4 投票 0

自定义用户字段的动态标签和 ACF

我正在尝试将 ACF 用于每个用户的自定义字段,然后我正在尝试使用 elementor pro 使用动态标签访问这些值。我创建了字段,为每个用户分配了值,但是...

回答 1 投票 0

使用高级自定义字段隐藏 divi 模块

希望有人能帮助我。 有没有办法在 Wordpress 中使用 ACF 切换 Divi 模块的可见性? 我自己试过,在论坛里搜索过

回答 1 投票 0

如果 ACF 返回格式是 Post Object,应用与 WP JSON 相同的 post 格式?

几天来我一直在努力实现“相关帖子”功能,不幸的是 PHP/Wordpress 不是我的强项。 目前我在我的前端点击了这个端点: ...

回答 1 投票 0

ACF 分类顺序

我创建了一个选择 Woocommerce 产品类别的 ACF 分类法字段。它具有多选外观,我想按多选顺序对分类法进行排序。 它正在工作,但只有

回答 1 投票 0

wordpress的警告:count(): Parameter must be an array or an object that implements Countable

Warning: count(): Parameter must be an array or an object that implements Countable in /home/vol1_4/epizy.com/epiz_33992342/htdocs/wp-includes/formatting.php on line 3443 注意:正在尝试访问...

回答 0 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.