Support » Plugin: Pods - Custom Content Types and Fields » Array Meta Query of a Custom Field ¿How?
Array Meta Query of a Custom Field ¿How?
-
In the posts I have created a custom field called actors. Also have created a CPT called CPTactors and I have related it to the previous custom field bidirectionally.
Now I want that when I access the page of the CPT-actors I get a list of all the posts that actor has.
$name = $post->post_name; //get the slug of the current CPTactors $args = array( 'post_type' => 'post', 'posts_per_page' => 199, 'meta_query' => array(array( 'key' => 'actors', 'value' => $name, 'compare' => 'LIKE', ), ), ); $loop = new WP_Query($args) . . .
I’m trying this but nothing comes out. any ideas?
-
This topic was modified 2 years ago by
virgilio27.
-
This topic was modified 2 years ago by
-
Nothing comes out, any way to see what the array contains?
Hi @virgilio27
Ah right, sorry, now I also see you’ve used the post name. You could use the post ID as these are stored in the database.
Cheers, Jory
Oh, and you can use
-1
forposts_per_page
if you want to fetch all relationships.Nothing. The strange thing is that if I leave it like that* the posts do come out, but all the posts that have any actor come out, not only those of that CPT.
*
$name = $post->post_name; //get the slug of the current CPTactors $args = array( 'post_type' => 'post', 'posts_per_page' => 199, 'meta_query' => array(array( 'key' => 'actors', ), ), ); $loop = new WP_Query($args)
Hi @virgilio27
You’ll still need to add the full meta query:
'key' => 'actors', 'value' => $post->ID, 'compare' => 'IN',
Cheers, Jory
Yeesss. It Works!!!
The error was in the field “value”, wasn’t it supposed to be the exact name?
No, relationships are always stored by their ID’s.
And you’re welcome! The best way to say thanks is to leave a 5 star review at https://wordpress.org/plugins/pods/ and (if you’re feeling especially generous) become a Friend of Pods at https://friends.pods.io/
Cheers, Jory
- The topic ‘Array Meta Query of a Custom Field ¿How?’ is closed to new replies.