我需要在可湿性粉剂的自定义函数过滤器中做一个var_dump,但是,结果显示在哪里?代码正在工作,因为我可以看到搜索结果结构与代码存在和不存在时的不同
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;
}
发布于 2015-03-07 01:53:42
尝试在var_dump之后立即终止流,这通常有助于我更轻松地进行调试:
var_dump($types);
die("products_first_ends");
这样,如果在var_dump之后呈现的内容位于var转储之上,它就不会被它覆盖。
发布于 2018-07-24 05:34:32
可以使用shutdown
钩子,将此代码添加到functions.php
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>";
});
}
发布于 2020-10-24 21:38:50
下面是一些好的和干净的东西:
if(!function_exists('wp_dump')) :
function wp_dump(){
if(func_num_args() === 1)
{
$a = func_get_args();
echo '<pre>', var_dump( $a[0] ), '</pre><hr>';
}
else if(func_num_args() > 1)
echo '<pre>', var_dump( func_get_args() ), '</pre><hr>';
else
throw Exception('You must provide at least one argument to this function.');
}
endif;
它的工作原理类似于var_dump()
,但更加简洁和格式化。
您可以向test传递无限数量的参数,而且每个转储之间的参数也是分开的。
https://stackoverflow.com/questions/28904648
复制相似问题