functions.php template_redirect打破了网站

时间:2018-06-19 10:44:29

标签: php wordpress function action

我在早期的WordPress安装中使用了以下功能,并且在那里工作正常。现在我想在另一个装置中使用它,但我得到一个白色的屏幕。

如果我带走下面的行动,他会。

add_action( 'template_redirect', 'when_a_review_gets_submitted' );

然后该功能不再正常工作。他必须检索page_ID,并且必须执行函数的其余部分。

有人知道为什么当前的功能不再起作用了吗?

这是完整的功能:

function when_a_review_gets_submitted ($review, $post_id) {

// Set up the objects needed
$hosting_provider_query = new WP_Query();
global $post;
$hosting_pagina_titel = $post->post_title;  
$search_all_pages = $hosting_provider_query->query(array(
    'post_type' => 'page',
    'post_status' => 'publish',
    //Only get pages where custom field 'name_hosting_provider' equals Page title
    'meta_query' => array(
        'relation' => 'AND',
        array(
            'key' => 'naam_hosting_provivder',
            'value' => $hosting_pagina_titel,
            'compare'   => '='
        ),

    ),
));

// Loop through all pages and find Page's children
$loop_through_all_child_pages = get_page_children( get_the_ID(), $search_all_pages );

// Loop through everything we got back
if(!empty($loop_through_all_child_pages)){
    foreach($loop_through_all_child_pages as $child_page){
        // get the ID of each childpage
        $get_child_page_ID = $child_page->ID;
        // get the ID of each parent page of the child pages
        $get_parent_page_ID = get_queried_object_id();
        // Get the average score from post_meta of the parent page
        $get_average_score = get_post_meta( $get_parent_page_ID, 'rwp_user_score', true );
        // update each custom field of the childs with the average score data from the post meta of parent page
        update_field('gemiddelde_score_hosting_provider', $get_average_score, $get_child_page_ID);
    }
}
}
add_action( 'template_redirect', 'when_a_review_gets_submitted' );
add_action('rwp_after_saving_review', 'when_a_review_gets_submitted', 11, 2);

修改 很抱歉没有发布调试信息:

致命错误:未捕获ArgumentCountError:函数when_a_review_gets_submitted()的参数太少,在/var/www/vhosts/domainname.nl/httpdocs/wp-includes/class-wp-hook.php中传入1在/var/www/vhosts/domainname.nl/httpdocs/wp-content/themes/hosting-vergelijker/functions.php:452预计286和2预期堆栈跟踪:#0 /var/www/vhosts/domainname.nl/ httpdocs / wp-includes / class-wp-hook.php(286):when_a_review_gets_submitted('')#1 /var/www/vhosts/domainname.nl/httpdocs/wp-includes/class-wp-hook.php(310) ):WP_Hook-> apply_filters(NULL,Array)#2 /var/www/vhosts/domainname.nl/httpdocs/wp-includes/plugin.php(453):WP_Hook-> do_action(Array)#3 / var /www/vhosts/domainname.nl/httpdocs/wp-includes/template-loader.php(12):do_action('template_redire ...')#4 /var/www/vhosts/domainname.nl/httpdocs/wp- blog-header.php(19):require_once('/ var / www / vhosts ...')#5 /var/www/vhosts/domainname.nl/httpdocs/index.php(17):require('/ var / www / vhosts ...')在/ var / www / vhosts中抛出#6 {main}第452行/domainname.nl/httpdocs/wp-content/themes/hosting-vergelijker/functions.php

1 个答案:

答案 0 :(得分:0)

template_redirect没有更多参数,您传递了2个参数,这是错误的,请参阅如何使用template_redirect https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect用户。

您无法在用于$review, $post_id过滤器的方法中通过template_redirect

相关问题