Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/258.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/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 在WordPress页面上运行自定义函数_Php_Arrays_Wordpress_Custom Fields - Fatal编程技术网

Php 在WordPress页面上运行自定义函数

Php 在WordPress页面上运行自定义函数,php,arrays,wordpress,custom-fields,Php,Arrays,Wordpress,Custom Fields,我的WordPress主题functions.php文件中有一个函数,包含以下代码: function locations() { $locations_list = array(); query_posts(array('orderby' => 'date', 'order' => 'DESC' , 'post_type' => 'location')); while(have_posts()) { $locations_list[the_

我的WordPress主题
functions.php
文件中有一个函数,包含以下代码:

function locations() {
    $locations_list = array();
    query_posts(array('orderby' => 'date', 'order' => 'DESC' , 'post_type' => 'location'));
    while(have_posts()) {
      $locations_list[the_slug()] = the_title();
    }
    wp_reset_query();
    return $locations_list;
}
我的想法是,我可以在我的网站上的任何地方运行这个功能,它将把我所有的帖子存储在一个数组中

然而,我不知道我是如何在公共端运行它的:'(

完美世界,我想在我的
footer.php
脚本中运行它

任何帮助都将不胜感激

完美世界,我想在footer.php脚本中运行它

然后从主题中运行footer.php模板中的函数

另外,避免对自定义查询使用
query\u posts()
,因为该函数会更改主查询。请直接使用该类:

$query = new WP_Query(array(...));
while($query->have_posts()) {
  $query->the_post();
  // $locations...
}

仅供参考,在屏幕上打印文章标题,因此您无需将其分配给变量,因为它不返回任何内容。

我将尝试一下。马上:-)