我已经阅读了大约20篇关于这个主题的不同帖子,但我仍然无法将解决方案应用到我遇到的问题上。很抱歉,我无法根据这些答案来解决这个问题,但我想知道是否有人可以帮助我解决我的特殊情况。我是php的初学者,请原谅我的无知。
我想在一篇帖子上创建一个查询,其中显示两个元键值(使用OR关系)与当前帖子ID匹配的其他帖子。
我的设置如下:
后元字段\'author_company\' - 将另一篇文章的详细信息存储为序列化数据,例如;a: 24:{s:2:ID:3:531:11:post-U作者:s:2:44:9:post-U日期:s:19:2015-12-18 10:35:43:13:发布时间:2015-12-18 10:35:43发布内容:581ta字段\'_pods_author_company\' - 这是由我用于CPTs的Pods插件创建的,它只存储帖子ID,但仍然以序列化格式,例如a:1:{I:0;I:531;}我有一个职位作为公司简介页面,我想在那里显示分配给该公司的所有职位。如何查找“author\\u company”或“pods\\u author\\u company”包含与此公司简介帖子匹配的ID的帖子?
E、 g.如果Example Company Ltd.的帖子ID为444,并且有一些帖子已分配给该公司,因此这些帖子上“author\\u Company”和/或“pods\\u author\\u Company”的序列化数据包含ID 444,我如何显示这些帖子?
以下是我如何获取所需数据的方法:
在公司简介栏上:
$post_id = get_the_ID(); //Get the ID of the current post (which is the company profile post)
在分配给该公司的岗位上:$author_company = get_post_meta( $post->ID, \'author_company\', true );
$author_company_id = $author_company[\'ID\']; //Get just the post ID from the serialized data
$_pods_company = get_post_meta( $post->ID, \'_pods_author_company\', true );
$_pods_company_id = $_pods_author_company[\'0\']; //Get just the post ID from the serialized data
我已经用var\\u dump进行了测试,这些测试确实得到了我需要的ID。To summarise: How can I query posts where $author_company_id OR $_pods_company_id MATCHES the current $post_id?
我知道将序列化数据用于元数据是一种非常糟糕的做法,但我不知道如何绕过它——这是Pods的工作方式。看起来我不得不把豆荚装进垃圾箱,尝试用另一种方式来做,但我真的不想这样。。。感谢您提供的任何帮助。