【问题标题】:PHP function, needed few input for post_type(wordpress theme function)PHP 函数,post_type 需要很少的输入(wordpress 主题函数)
【发布时间】:2014-05-03 12:01:52
【问题描述】:

wordpress主题功能内的功能

function child_post_list($title){
$args = array('posts_per_page'=>1, 'post_type' => 'updatelist');
$update_list_post = get_posts( $args ); //UPDATE LIST post
if(isset($update_list_post[0])){
    $args = array('meta_key'=>'_wpcf_belongs_updatelist_id', 'meta_value' => $update_list_post[0]->ID,'post_type' => "'indon-stat';'myanmar-stat'");
    $child_posts = get_posts( $args ); //the child listing of UPDATE LIST post
    foreach($child_posts as $post){
        if(get_post_meta($post->ID, 'wpcf-biodata-code', true) == $title){ //if the post title is exist within the custom field of the child listing of UPDATE LIST post.
            return 1;
        }
    }
}

}

如你所见,代码的最后部分

"'indon-stat';'myanmar-stat'");

这绝对是错误的语法,所以我想问一下什么是正确的?甚至可以为此插入多个帖子类型吗?

【问题讨论】:

  • 这取决于您的应用程序。您可以使用数组、逗号或空格。但是,如果我们不了解足够的信息,我们将无能为力。
  • 已编辑问题,认为我应该让它简单,我在 php 方面真的很糟糕
  • wordpress 是的,谢谢
  • @AD7six 这不是你说的那样,因为它更像是从多种帖子类型中检索
  • 请编辑问题 - 不要写 cmets。

标签: php wordpress function


【解决方案1】:

如果要插入多个帖子类型,请尝试将其插入为逗号分隔值或 JSON 字符串

'post_type' => "indon-stat,myanmar-stat"

【讨论】:

  • 条件表达式中包含非法字符
猜你喜欢
  • 2015-12-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-04
  • 1970-01-01
  • 2017-10-25
  • 2012-06-01
相关资源
最近更新 更多