duanqi6274 2018-02-02 10:19
浏览 34


I'm trying to add a meta box for my custom post type (which is inside a plugin).

I want to get all pages that are assigned a particular page template in my Wordpress site, so I use the following:

$surgeons = get_pages(array(
    'meta_key' => '_wp_page_template',
    'meta_value' => 'template-meet-the-team-single.php'

However, $surgeons is returned as an empty array, why?

It sounds like no page is using the template I'm stating, as if I just use the default get_pages() it returns all pages, but this is incorrect as I definitely have pages that are assigned this template.

Does it matter that this code is in a plugin file, and the meta_value is trying to locate this template in the plugin folder?

  • 写回答

2条回答 默认 最新

  • dongxiee0744 2018-02-04 09:00

    Although I don't think this really provides an answer to the issue I Was having, this was the way to fix the array being returned and provide the correct results.

    Instead of using get_pages(), I simply switched it to get_posts(), which then returned the correct results.

    $surgeons = get_posts(array(
        'post_type' => 'page',
        'posts_per_page' => -1,
        'meta_key' => '_wp_page_template',
        'meta_value' => 'template-meet-the-team-single.php'
    本回答被题主选为最佳回答 , 对您是否有帮助呢?



  • ¥20 C#调用虚拟键盘TabTip.exe
  • ¥15 Qt4代码实现下面的界面
  • ¥15 CCS离散化传递函数与仿真不一致
  • ¥15 prism提示我reinstall prism 如何解决
  • ¥15 asp.core 权限控制怎么做,需要控制到每个方法
  • ¥20 while循环中OLED显示中断中的数据不正确
  • ¥15 这个视频里的stm32f4代码是怎么写的
  • ¥15 JNA调用DLL报堆栈溢出错误(0xC00000FD)
  • ¥15 请教SGeMs软件的使用
  • ¥15 自己用vb.net编写了一个dll文件,如何只给授权的用户使用这个dll文件进行打包编译,未授权用户不能进行打包编译操作?