如何通过关系字段值查询自定义帖子类型

时间:2018-01-16 22:01:45

标签: php wordpress

为什么根据帖子的perma-link查询页面会给我一个错误:

foreach ($serv as $servi) : //$serv is my array
    $the_id = $servi->ID; // 94093
    $get_perma_basename = basename(get_permalink($the_id)); //http://www.mywes.com/serv/my-page -> my-page
    $get_prov = get_posts(array(
         'post_type' => 'my_custom_post_type',
         'meta_query' => array(
          array(
                'key' => 'serv', // name of the relationship field in all post with the custom post type
                'value' => '"' . get_perma_basename . '"', //compare to see which entry in my custom post type has the `my-page` value
                'compare' => 'LIKE'
                    )
                )
            ));

我收到以下错误:

Notice: Use of undefined constant get_perma_basename - assumed 'get_perma_basename' in /var/www/my_site/check-for-page.php on line 310

310'value' => '"' . get_perma_basename . '"'

如何解决问题以便正确查询

1 个答案:

答案 0 :(得分:2)

尝试$get_perma_basename(变量)而不是get_perma_basename(常量)。