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

问题描述 投票:0回答:1

为什么基于帖子的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 . '"'

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

php wordpress
1个回答
2
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.