Php 使用方法获取元数据并作为数组返回
我有下面的方法,我想从数据库中检索一些详细信息,并在我的方法中返回它们: 下面是我的Php 使用方法获取元数据并作为数组返回,php,wordpress,class,Php,Wordpress,Class,我有下面的方法,我想从数据库中检索一些详细信息,并在我的方法中返回它们: 下面是我的get\u方法: public function get_authors() { // @todo: Return an array of profile objects // @todo: This should turn an array of profiles $profiles = get_post_meta(get_the_ID(),'auth
get\u方法
:
public function get_authors()
{
// @todo: Return an array of profile objects
// @todo: This should turn an array of profiles
$profiles = get_post_meta(get_the_ID(),'author', true);
var_dump($profiles);
return $profiles;
}
以下是$profiles
var\u dump的内容:在我的数据库中链接为“作者”的内容:
在我的
wp_posts
中,这两个ID链接到posts-我将如何在我的方法中提取这些posts
这里,这将简单地循环作者,并获得每个作者的帖子。因此,您基本上希望返回那些作者在“简介”中发表的帖子?@ebrahimmohamed,正确,我正在输出一个foreach,它只返回这些配置文件的名称-每个“作者”ID都链接到一个wp_post您希望它的格式是:数组(['834']=>posts_数组,['839']=>posts_数组)还是类似的格式?这里的键是作者id?我想使用作者id,只需要获得特定于这些id@EbrahimMohammed.的帖子的输出。。假设我们有作者的ID 834,这是
wp_posts
中的一篇帖子-我想把这两篇完整的帖子放到一个数组中@Ebrahim太多了-我尝试过这个方法,当我var_dump$final_数组时,我得到了空数组结果。啊,两位作者的结果都是空的?是的,我已经更新了上面的图形-给我30秒。明白了吗,给我点时间调试一下!这是我的荣幸,伙计!哇,这太奇怪了,它应该可以工作了:O你介意去数据库和posts表查询这样的内容吗:选择*FROMposts
WHEREpost\u author
='834',但用posts表替换“posts”!
public function get_authors()
{
// @todo: Return an array of profile objects
// @todo: This should turn an array of profiles
$profiles = get_post_meta(get_the_ID(),'author', true);
$final_array = array();
foreach($profiles as $profile){
$final_array[$profile] = get_posts([
'author' => $profile,
'orderby' => 'date',
'order' => 'DESC'
]);
}
return $final_array;
}