Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何进入循环_Php_Wordpress - Fatal编程技术网

Php 如何进入循环

Php 如何进入循环,php,wordpress,Php,Wordpress,我了解到,$post对象必须在循环中访问。 目前,以下代码不记录任何内容 global $post; error_log(print_r($post, true)); 我想这是因为我没有参与其中。 那么,访问此循环的方法是什么?我们可以通过一些钩子或过滤器访问它吗?对于任何感兴趣的人,您可以使用以下钩子进入循环: add_action( 'loop_start', 'myfunction'); function myfunction() { global

我了解到,$post对象必须在循环中访问。 目前,以下代码不记录任何内容

    global $post;      
    error_log(print_r($post, true));
我想这是因为我没有参与其中。
那么,访问此循环的方法是什么?我们可以通过一些钩子或过滤器访问它吗?

对于任何感兴趣的人,您可以使用以下钩子进入循环:

add_action( 'loop_start', 'myfunction');

function myfunction() {

    global $post;
    error_log(print_r($post, true));   // on this hook $posts should log

}

myfunction
中的所有代码都保证在循环中

循环是WP开发的基本部分:每个页面或帖子都是“循环”的一部分(尽管对于单个帖子来说,它是一个1篇帖子的循环)。您试图在哪里使用此代码?如果您已连接到某个操作,则可能是某个特定操作在生成循环之前正在运行。