I've read about 20 different posts on this topic and I still can't apply the solutions to the problem I'm having. I'm very sorry for not being able to figure it out based on those answers, but I wonder if someone could help me with my particular situation. I'm a beginner at php, so please forgive my ignorance.
I want to create a query on a post which displays other posts where two meta key values match (with an OR relationship) the post ID of the current post.
My setup is as follows:
- Post meta field 'author_company' - Stores the details of another post as serialized data, e.g. "a:24:{s:2:""ID"";s:3:""531"";s:11:""post_author"";s:2:""44"";s:9:""post_date"";s:19:""2015-12-18 10:35:43"";s:13:""post_date_gmt"";s:19:""2015-12-18 10:35:43"";s:12:""post_content"";s:581:""...
- Post meta field '_pods_author_company' - This was created by the Pods plugin I'm using for CPTs, and it stores just the post ID but still in a serialized format, e.g. a:1:{i:0;i:531;}
I have a post acting as company profile page, where I want to display all the posts which have been assigned to that company. How can I find posts where 'author_company' OR '_pods_author_company' contains the ID matching this company profile post?
E.g. if Example Company Ltd. has a post ID of 444, and there are some posts which have been assigned to that company and therefore the serialized data for 'author_company' and/or '_pods_author_company' on those posts contain the ID 444, how do I display those posts?
Here's how I can get the data I need:
On the company profile post:
$post_id = get_the_ID(); //Get the ID of the current post (which is the company profile post)
On the posts assigned to that company:
$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
I have tested with var_dump and those do indeed result in just the ID I need.
To summarise: How can I query posts where $author_company_id OR $_pods_company_id MATCHES the current $post_id?
I know it's very bad practice to use serialized data for meta values, but I don't know how to get around it - it's how Pods works. It's looking like I'm going to have to bin Pods and try and do this another way, but I really don't want that to be the case...
Thanks for any assistance you can provide.