在嵌套转发器中更新帖子对象高级自定义字段

时间:2015-07-27 15:57:28

标签: php wordpress advanced-custom-fields

我已经坚持了一个月左右,现在已经没时间完成了!

基本上(请参阅下面的print_R)我有一个名为' Penguin'我在ACF创建的。我的网站的功能允许这些企鹅'企鹅'为了参加游泳比赛,我有另一种名为“赛事”的帖子类型。这是他们将要进入​​的事件。我有一个名为Fixture的帖子类型,它有一个名为' event_selector'的转发器。事件' post type是一个重复的post对象,然后是一个名为' standings'的转发器字段。在那之内。在这个中继器领域内是企鹅'企鹅'邮寄对象。

当使用后端使用企鹅添加和更新事件时,它可以正常工作,但是当尝试使用update_field()/ update_sub_field()在前端进行更新时,没有任何反应!我不知道如何继续尝试解决这个问题。我添加了一个print_r的转发器字段和我想用来更新字段以添加更多企鹅的代码,我希望有人可以提供帮助!

<?php
$fixtureArgs = array( 
    'post_type' => 'fixture', 
    'post_id' => $fixtureID );

$fixtureLoop = new WP_Query($fixtureArgs);

if($fixtureLoop->have_posts()) : 
    while($fixtureLoop->have_posts()) : $fixtureLoop->the_post(); 
        if(get_the_ID() == $fixtureID) : 
            $field_key = 'event_selector';
            $post_id = $childID;
            $value = get_field($field_key, $post_id);
            $value[] = array(
                'standings' => array(array('penguin' => $value))
            );
            update_field($field_key, $value, $post_id);
        endif; 
    endwhile; 
endif; 

的print_r:

<?php
    print_r:
    (
        [0] => Array
            (
                [event] => WP_Post Object
                    (
                        [ID] => 526
                        [post_author] => 1
                        [post_date] => 2015-05-26 15:38:04
                        [post_date_gmt] => 2015-05-26 15:38:04
                        [post_content] =>
                        [post_title] => 100m IM
                        [post_excerpt] =>
                        [post_status] => publish
                        [comment_status] => closed
                        [ping_status] => closed
                        [post_password] =>
                        [post_name] => 100m-im
                        [to_ping] =>
                        [pinged] =>
                        [post_modified] => 2015-05-26 15:38:04
                        [post_modified_gmt] => 2015-05-26 15:38:04
                        [post_content_filtered] =>
                        [post_parent] => 0
                        [guid] => http://wcpsc.users41.interdns.co.uk/?post_type=event&p=526
                        [menu_order] => 0
                        [post_type] => event
                        [post_mime_type] =>
                        [comment_count] => 0
                        [filter] => raw
                    )
                [event_time] => 12.00pm
                [standings] => Array
                    (
                        [0] => Array
                            (
                                [penguin] => WP_Post Object
                                    (
                                        [ID] => 440
                                        [post_author] => 1
                                        [post_date] => 2015-02-17 12:34:31
                                        [post_date_gmt] => 2015-02-17 12:34:31
                                        [post_content] =>
                                        [post_title] => Alex Lancaster
                                        [post_excerpt] =>
                                        [post_status] => publish
                                        [comment_status] => closed
                                        [ping_status] => closed
                                        [post_password] =>
                                        [post_name] => alex-lancaster
                                        [to_ping] =>
                                        [pinged] =>
                                        [post_modified] => 2015-05-20 13:53:42
                                        [post_modified_gmt] => 2015-05-20 13:53:42
                                        [post_content_filtered] =>
                                        [post_parent] => 0
                                        [guid] => http://wcpsc.ice/?post_type=penguin&p=440
                                        [menu_order] => 0
                                        [post_type] => penguin
                                        [post_mime_type] =>
                                        [comment_count] => 0
                                        [filter] => raw
                                    )
                                [time] =>
                            )
                        [1] => Array
                            (
                                [penguin] => WP_Post Object
                                    (
                                        [ID] => 453
                                        [post_author] => 1
                                        [post_date] => 2015-05-20 13:15:56
                                        [post_date_gmt] => 2015-05-20 13:15:56
                                        [post_content] =>
                                        [post_title] => Bob Saget
                                        [post_excerpt] =>
                                        [post_status] => publish
                                        [comment_status] => closed
                                        [ping_status] => closed
                                        [post_password] =>
                                        [post_name] => bob-saget
                                        [to_ping] =>
                                        [pinged] =>
                                        [post_modified] => 2015-05-21 14:03:43
                                        [post_modified_gmt] => 2015-05-21 14:03:43
                                        [post_content_filtered] =>
                                        [post_parent] => 0
                                        [guid] => http://wcpsc.users41.interdns.co.uk/?post_type=penguin&p=453
                                        [menu_order] => 0
                                        [post_type] => penguin
                                        [post_mime_type] =>
                                        [comment_count] => 0
                                        [filter] => raw
                                    )
                                [time] =>
                            )
                        [2] => Array
                            (
                                [penguin] => WP_Post Object
                                    (
                                        [ID] => 481
                                        [post_author] => 1
                                        [post_date] => 2015-05-26 12:32:35
                                        [post_date_gmt] => 2015-05-26 12:32:35
                                        [post_content] =>
                                        [post_title] => Daughter
                                        [post_excerpt] =>
                                        [post_status] => publish
                                        [comment_status] => closed
                                        [ping_status] => closed
                                        [post_password] =>
                                        [post_name] => daughter
                                        [to_ping] =>
                                        [pinged] =>
                                        [post_modified] => 2015-05-26 12:32:35
                                        [post_modified_gmt] => 2015-05-26 12:32:35
                                        [post_content_filtered] =>
                                        [post_parent] => 0
                                        [guid] => http://wcpsc.users41.interdns.co.uk/?post_type=penguin&p=481
                                        [menu_order] => 0
                                        [post_type] => penguin
                                        [post_mime_type] =>
                                        [comment_count] => 0
                                        [filter] => raw
                                    )
                                [time] =>
                            )
                        [3] => Array
                            (
                                [penguin] => WP_Post Object
                                    (
                                        [ID] => 439
                                        [post_author] => 1
                                        [post_date] => 2015-02-17 12:33:54
                                        [post_date_gmt] => 2015-02-17 12:33:54
                                        [post_content] =>
                                        [post_title] => Little Jimmy
                                        [post_excerpt] =>
                                        [post_status] => publish
                                        [comment_status] => closed
                                        [ping_status] => closed
                                        [post_password] =>
                                        [post_name] => little-jimmy
                                        [to_ping] =>
                                        [pinged] =>
                                        [post_modified] => 2015-05-21 14:01:44
                                        [post_modified_gmt] => 2015-05-21 14:01:44
                                        [post_content_filtered] =>
                                        [post_parent] => 0
                                        [guid] => http://wcpsc.ice/?post_type=penguin&p=439
                                        [menu_order] => 0
                                        [post_type] => penguin
                                        [post_mime_type] =>
                                        [comment_count] => 0
                                        [filter] => raw
                                    )
                                [time] =>
                            )
                        [4] => Array
                            (
                                [penguin] => WP_Post Object
                                    (
                                        [ID] => 455
                                        [post_author] => 1
                                        [post_date] => 2015-05-21 14:05:16
                                        [post_date_gmt] => 2015-05-21 14:05:16
                                        [post_content] =>
                                        [post_title] => The Master Chief
                                        [post_excerpt] =>
                                        [post_status] => publish
                                        [comment_status] => closed
                                        [ping_status] => closed
                                        [post_password] =>
                                        [post_name] => the-master-chief
                                        [to_ping] =>
                                        [pinged] =>
                                        [post_modified] => 2015-05-22 11:24:22
                                        [post_modified_gmt] => 2015-05-22 11:24:22
                                        [post_content_filtered] =>
                                        [post_parent] => 0
                                        [guid] => http://wcpsc.users41.interdns.co.uk/?post_type=penguin&p=455
                                        [menu_order] => 0
                                        [post_type] => penguin
                                        [post_mime_type] =>
                                        [comment_count] => 0
                                        [filter] => raw
                                    )
                                [time] =>
                            )
                    )
            )
    )
?>

0 个答案:

没有答案