duanduanxi9441 2018-06-19 10:44
浏览 146

functions.php template_redirect打破了网站

I used the function below in an earlier WordPress installation and that worked fine there. Now I want to use it in another installation but there I get a white screen.

If I take away the action below, he will.

add_action( 'template_redirect', 'when_a_review_gets_submitted' );

but then the function no longer works as it should. He would have to retrieve the page_ID and the rest of the function would have to be executed.

Someone an idea why the current function no longer works?

This is the complete function:

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);

EDIT Sorry for not posting debug information:

Fatal error: Uncaught ArgumentCountError: Too few arguments to function when_a_review_gets_submitted(), 1 passed in /var/www/vhosts/domainname.nl/httpdocs/wp-includes/class-wp-hook.php on line 286 and exactly 2 expected in /var/www/vhosts/domainname.nl/httpdocs/wp-content/themes/hosting-vergelijker/functions.php:452 Stack trace: #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...') #6 {main} thrown in /var/www/vhosts/domainname.nl/httpdocs/wp-content/themes/hosting-vergelijker/functions.php on line 452

  • 写回答

1条回答 默认 最新

  • doutan3192 2018-06-19 11:07
    关注

    template_redirect has no more parameters and you passed 2 parameteres which is wrong refer this how to user template_redirect hook https://codex.wordpress.org/Plugin_API/Action_Reference/template_redirect.

    You can't pass $review, $post_id in method which is used for template_redirect filter.

    评论

报告相同问题?

悬赏问题

  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档