标签: advanced-custom-fields

创建功能以替换帖子标题不起作用

我正在尝试在内部创建一个函数functions.php,用来自多个自定义字段的信息替换自定义帖子标题.在发布帖子之前,我想评估它是否已经创建或者这是一个新帖子; 如果是新帖子,我想从多个字段中获取信息,计算此自定义帖子类型中的帖子总数并创建标题; 如果这只是编辑已经存在的帖子,我想使用该$_POST['post_title']字段内的内容.

function custom_field_value_as_title( $value, $post_id, $field ) {
    global $_POST;

    // vars
    $title = $_POST['post_title'];
    $post = get_page_by_title( $title, 'OBJECT', 'mascotas' );

    if ( FALSE === get_post_status( $post_id ) ) {

        $new_title_ciudad = get_field('ciudad', $post_id);
        $new_title_sexo = get_field('sexo', $post_id);
        $new_title_especie = get_field('especie' , $post_id);
        $registered_year = date("y");

        $count_mascotas = wp_count_posts('mascotas');
        $next_count = $count_mascotas->publish + 1;
        $new_count = sprintf("%04d", $next_count);

        $new_title = "$new_title_ciudad"."$new_title_sexo"."$new_title_especie"."$registered_year"."-"."$new_count";

    // update post
        $my_post = array(
            'ID'         => $post_id,
            'post_title' => $new_title, …
Run Code Online (Sandbox Code Playgroud)

php wordpress advanced-custom-fields

9
推荐指数
1
解决办法
710
查看次数

在functions.php中包含ACF(WordPress)

我是第一次以主题forrest的形式出售主题.我在开发过程中使用ACF作为标准插件,以确保一切正常.

我已经差不多完成了,从而决定导出我ACFPHP并将其包含到我的functions.php文件.

我复制/粘贴它给了我进入代码functions.php,其中包括ACF,options-page,和repeater-field在我的主题中的一个文件夹,并相应地引用它们.

但是,当我访问我的网站时,我收到此错误:

Fatal error: Cannot redeclare class Acf in /Applications/MAMP/htdocs/omg/wp-content/themes/omg-v1/external/acf/acf.php on line 46

我也从plugins文件夹中删除了实际的插件文件.

任何想法为什么它可能会被淘汰?

我知道这是很多代码,但是任何人都希望看到这是我的代码functions.php(ACF给了我)

include_once('external/acf/acf.php' );
define( 'ACF_LITE' , true );

// Add-ons 
include_once('external/acf-repeater/acf-repeater.php');
include_once('external/acf-options-page/acf-options-page.php');



if(function_exists("register_field_group"))
{
    register_field_group(array (
        'id' => 'acf_featured-story',
        'title' => 'Featured Story',
        'fields' => array (
            array (
                'key' => 'field_5256bd0fc7592',
                'label' => 'Is this story featured?',
                'name' => 'featured-story',
                'type' => 'true_false',
                'message' => 'Yes', …
Run Code Online (Sandbox Code Playgroud)

php wordpress advanced-custom-fields

8
推荐指数
1
解决办法
1万
查看次数

R中ACF和PACF的显着性水平

我想获得确定自相关系数和部分自相关系数重要性的限制,但我不知道该怎么做.

我使用此功能获得了Partial autocorrelogram pacf(data).我希望R打印出图中所示的值.

在此输入图像描述

r significance advanced-custom-fields

8
推荐指数
2
解决办法
6318
查看次数

高级自定义字段显示最后三个子转发器行

我正在使用高级自定义字段(ACF)从事件页面提取转发器信息,并在主页上显示事件的缩短列表.

我已经设置了一个转发器,允许用户输入事件发生的月份(允许它们放入多个月的事件),然后是子转发器,允许它们为给定的月份添加多个事件.示例如下:

游行

  • 3月9日的活动
  • 3月12日的活动
  • 3月28日活动

四月

  • 4月1日活动
  • 4月28日活动

这是事件页面上的当前输出,它按预期工作.

在网站的主页上,我需要将最新的3个事件(列表底部的事件是最新事件)拉出来并显示在主页上.

我在主页上拉动和显示事件时没有问题.我遇到的问题是显示最后三个事件(子转发器)在月份之间交叉的事件(父转发器).

简单地使用跨越if,while,语句的php循环限制事件输出仅限制该月输出的事件数.我目前在主页上使用的代码如下.

<?php if( have_rows('event_month', 1263)): ?>
<ul>
    <?php while ( have_rows('event_month', 1263) ) : the_row(); ?>
        <?php if( have_rows('event', 1263)):;   ?>
            <?php while ( have_rows('event', 1263) ) : the_row(); ?>
                <li>
                    <h3>
                        <a href="<?php echo esc_url( home_url( '/' ) ); ?>events/"><?php $summary = get_sub_field('event_title');
                            echo substr($summary, 0, 34),'...'; ?></a>
                            <span><?php the_sub_field('event_day_of_week');?>, <?php the_sub_field('event_sub_month');?> <?php the_sub_field('event_day');?></span>
                    </h3>
                </li>
            <?php endwhile; ?>
        <?php else: ?>
            <p>Show dates to be announced …
Run Code Online (Sandbox Code Playgroud)

php wordpress nested-loops advanced-custom-fields

8
推荐指数
1
解决办法
957
查看次数

自定义帖子类型和页面层次结构 - 错误404

我已经定义了两种自定义帖子类型:

  • 主题
  • 菲切

我还使用定义的rubrique模板打了7页:(template-rubrique.php)

我的主题Fiche都有一个ACF后对象字段.

  • Theme ACF post-object字段用于定位Rubrique.
  • Fiche ACF post-object字段用于定位主题.

我希望我的CPTS URL采用以下格式:example.com/myRubriqueName/myThemeName/myFicheName.

myRubriqueName是一个页面,而myThemeNamemyFicheName是CPT.


到目前为止,我所有的fiche主题帖子URL都生成得很好,但它们最终都在404页面中.此外,我的帖子和页面被重定向到头版.

我正在使用这篇文章中的代码,我试图根据自己的情况进行调整.


CPT注册:

register_post_type('theme', array(
    'labels' => array(
        'name' => 'Thèmes',
        'singular_name' => 'Thème',
    ),
    'public' => true,
    'has_archive' => false,
    'hierarchical' => false,
    'menu_icon' => 'dashicons-art',
    'rewrite' => array(
        'slug' => '%rubrique%', // %rubrique% is used as placeholder
        'with_front' => …
Run Code Online (Sandbox Code Playgroud)

php wordpress http-status-code-404 custom-post-type advanced-custom-fields

8
推荐指数
1
解决办法
196
查看次数

wp_query 和 meta_query 用于转发器字段值

我有一个带有自定义字段的文字新闻网站。我需要将转发器字段作为表进行查询。它看起来像这样:

        | param_1 | param_2 | param_2  | param_4
        |    20   |   20    | 20       |   20
        |    555  |   680   | 56       |    0
        |    5555 |   45    | 56       |    1
        |    69   |   0     | 45       |    0
Run Code Online (Sandbox Code Playgroud)

只有当它与同一行中的查询匹配时,我才需要查询此转发器以获取结果

我的元查询看起来像这样:

[post_type] => product
[posts_per_page] => -1
[orderby] => title
[order] => ASC
[meta_query] => Array (
    [relation] => AND
    [0] => Array (
        [key] => BBBproduct_params_values_AAA_param_value_0
        [value] => 25
        [compare] => <=
        [type] => NUMERIC
        )
    [1] …
Run Code Online (Sandbox Code Playgroud)

wordpress repeater advanced-custom-fields meta-query

8
推荐指数
1
解决办法
529
查看次数

当使用其他语言更新同一转发器字段的值时,ACF 转发器字段中的值是否为空?

我有一个使用三种语言的站点,当我编辑其中一种语言的转发器字段时,其他语言的转发器字段的值变为空。这仅适用于站点中的某些转发器字段。

php wordpress wpml advanced-custom-fields

8
推荐指数
1
解决办法
218
查看次数

ACF关系字段 - 来自其他帖子类型的get_field值

在我的POSTS页面(常规帖子类型)中,我设置了一个ACF关系字段.在这里我可以选择公司名称,这些名称都在directory_listings的post类型下.

现在,我在目录列表页面上有以下代码,因此使用简单的get_field不起作用,因为这些值不在此页面上,而是在POST类型的其他位置.

所以不确定如何获取信息.

DIRECTORY_LISTINGS帖子类型下的其中一个页面上的代码:

$posts = get_field('related_articles');

if( $posts ): ?>
    <ul>
    <?php foreach( $posts as $post): // variable must be called $post (IMPORTANT) ?>
        <?php setup_postdata($post); ?>
        <li>
            <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        </li>
    <?php endforeach; ?>
    </ul>
    <?php wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly ?>
<?php endif; ?>
Run Code Online (Sandbox Code Playgroud)

示例图,因为我不太通过文本解释. 在此输入图像描述

目前,我已在公司编辑页面(directory_listing)上设置了关系字段.它执行以下操作时:1)此商家列表的相关帖子 - >选择帖子 - >发布 - >现在显示商家列表页面上的列表.示例:http://bit.ly/1vwydDl(页面底部)

2)我想从POST编辑页面选择一个将发布帖子的商家.我可以通过ACF将该字段放在那里没有问题,但让它实际显示我无法弄清楚的结果.

wordpress advanced-custom-fields

7
推荐指数
1
解决办法
2万
查看次数

点击其他时更改Google地图标记图标

我使用高级自定义字段Google地图字段创建了Google地图多个位置页面.

我已设法在单击时更改标记图标,但我希望在单击其他图标时将其更改回来.

这是代码的一个例子:

    for (i = 0; i < locations.length; i++) {  
  marker = new google.maps.Marker({
    position: new google.maps.LatLng(locations[i][1], locations[i][2]),
    map: map,
    icon: iconBase + 'Stock%20Index%20Up.png'
  });

  google.maps.event.addListener(marker, 'click', (function(marker, i) {
    return function() {
      infowindow.setContent(locations[i][0], locations[i][6]);
      infowindow.open(map, marker);
      marker.setIcon("https://cdn3.iconfinder.com/data/icons/musthave/24/Stock%20Index%20Down.png");
    }
  })(marker, i));
Run Code Online (Sandbox Code Playgroud)

在这里更好地了解工作代码:http: //jsfiddle.net/gargiguy/s8vgxp3g

javascript google-maps-api-3 google-maps-markers advanced-custom-fields

7
推荐指数
1
解决办法
1万
查看次数

使用meta_query进行复杂的custom_field搜索

背景

我使用Advanced Custom Fields Pro管理我的自定义字段,它们有一个"repeater"字段,其中包含存储的子字段,repeatername_X_fieldname其中X是转发器的行号.

我有一个自定义的帖子类型student,attendance其中包含date和包含的转发器class.

因此,当学生上课时,它将按如下方式存储他们的出勤率

  • meta_key: 'attendance_X_date' meta_value: '20170701'
  • meta_key: 'attendance_X_class' meta_value: '历史101'

为了搜索任何已经去过某个班级或在某个日期范围内就读的学生,我必须挂钩get_meta_sql并将我转换meta_query为使用LIKE而不是=当值包含时%

function key_rewrite($parts){
    foreach($parts as &$part){
        $part = preg_replace("/(meta_key = )(\'[^']*[%][^']*\')/", "meta_key LIKE $2", $part);
    }
    return $parts;
}
add_action( 'get_meta_sql', 'key_rewrite');
Run Code Online (Sandbox Code Playgroud)

这让我可以做类似的事情

$args = array(
    'post_type' => 'student',
    'meta_query' => array(
        array(
            'key'=>'attendance_%_class',
            'compare'=>'=',
            'value'=>'History 101'
        )
    )
);
$my_query = …
Run Code Online (Sandbox Code Playgroud)

wordpress custom-fields advanced-custom-fields

7
推荐指数
1
解决办法
623
查看次数