WordPress-根据元字段内容获取帖子 [英] Wordpress - get post based on meta field content

查看:130
本文介绍了WordPress-根据元字段内容获取帖子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个wordpress插件.我使用的是两种不同的自定义帖子类型,玩家团队.

I'm developing a wordpress plugin. I'm using two different custom post types, players and teams.

  • 玩家具有相关的元字段:名,姓和队.
  • 团队具有团队名称的相关元字段.
  • Players has relevant meta fields: First name, last name, and team.
  • Teams has relevant meta fields of team name.

在编辑特定的团队帖子时,我正在尝试对所有发布了该团队名称的所有玩家进行排序到他们的团队名称的元字段中.我不确定该怎么做.任何帮助或文章都会非常有帮助.谢谢

While editing a specific team post, I'm trying to have an array of all the players that currently have that team's name posted to their meta field for team name. I'm not sure how to do this. Any help or articles would be really helpful. Thanks

推荐答案

重要的是,您至少要使用帖子类型,元键和元值的三个条件来查询帖子.

The important thing is that you are querying for posts using at least the three criteria of the post type, meta key, and meta value.

例如,假设您的自定义帖子类型仅称为玩家",并且每个玩家"帖子都有一个名为"player_team"的元字段

For example, let's assume your custom post type is just called "player" And, each 'player' post has a meta field attached called "player_team"

然后您可以使用类似以下内容的查询这些帖子:

You could then query for those posts using something like this:

$teamname = ""; // the player's team that you're querying for

$myquery = new WP_Query( "post_type=player&meta_key=player_team&meta_value=$teamname&order=ASC" );

这篇关于WordPress-根据元字段内容获取帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆