Wordpress var_dump in functions.php

2019-05-07 08:22发布

I need to do a var_dump in a custom function filter in WP but, where is the results shown? The code is working because I can see the search result structure difference from when the code is present and not

    add_filter('relevanssi_hits_filter', 'products_first');
function products_first($hits) {
    $types = array();

    $types['section1'] = array();
    $types['section2'] = array();
    $types['section3'] = array();
    $types['section4'] = array();

    // Split the post types in array $types
    if (!empty($hits)) {
        foreach ($hits[0] as $hit) {
            array_push($types_1[$hit->post_type], $hit);
        }
    }

    // Merge back to $hits in the desired order
    var_dump($types);
    $hits[0] = array_merge($types['section1'], $types['section2'], $types['section3'], $types['section4']);
    return $hits;
}

标签: php wordpress
2条回答
狗以群分
2楼-- · 2019-05-07 09:01

shutdown hook can be used to render before closing body tag:

function custom_dump($anything){
  add_action('shutdown', function () use ($anything) {
    echo "<div style='position: absolute; z-index: 100; left: 30px; bottom: 30px; right: 30px; background-color: white;'>";
    var_dump($anything);
    echo "</div>";
  });
}
查看更多
【Aperson】
3楼-- · 2019-05-07 09:19

Try killing the flow right after the var_dump, that ussually helps me debug easier:

var_dump($types);
die("products_first_ends");

That way if something after your var_dump is rendering on top of the var dump it wont get covered by it.

查看更多
登录 后发表回答