Note that there are some explanatory texts on larger screens.

plurals
  1. POquery post with custom field value in Array
    primarykey
    data
    text
    <p>my custom field vardump() for a post with a good value (12 ) is : </p> <pre><code> Custom_field = array(1) { [0]=&gt; int(12) } </code></pre> <p>and my args for my query is : </p> <pre><code>$artistArg = array( 'numberposts' =&gt; -1, 'category_name' =&gt; 'oeuvres', 'meta_query' =&gt; array( array( 'key' =&gt; 'Custom_field', 'compare' =&gt; 'EXISTS', 'value' =&gt; array(12,29,34) ) ) ); </code></pre> <p>It's not working... if I remove the value from the args it returns all the post, but when I pass the value in it returns nothing, I tried to change compare to "=" or "IN" also...I guess I'm doing something wrong here...(and I also tried with a "non array" custom field and everything works fine...) thank you</p> <p><strong>EDIT :</strong> As I don't find the solution right now i just do that :</p> <pre><code>&lt;?php //Get the value $authorId = get_the_ID(); //query the post with the good meta_key $artistArg = array( 'numberposts' =&gt; -1, 'category_name' =&gt; 'oeuvres', 'meta_query' =&gt; array( array( 'key' =&gt; 'artiste' ) ) ); //In the query I just filter the results with the given array of the custom field... $artDisplay = new WP_Query( $artistArg ); // The Loop if ( $artDisplay-&gt;have_posts() ) { echo '&lt;h2&gt;Art: &lt;/h2&gt;&lt;ul id="discover"&gt;'; while ( $artDisplay-&gt;have_posts() ) { $artDisplay-&gt;the_post(); $artiste = get_field('artiste'); if ($artiste[0] == $authorId): echo '&lt;li&gt;'; echo "&lt;div class='thumbDiscover'&gt;"; echo "&lt;a href='".get_permalink()."'&gt;"; the_post_thumbnail('thumb'); echo "&lt;/a&gt;"; echo "&lt;/div&gt;&lt;span&gt;"; echo "&lt;a href='".get_permalink()."'&gt;"; the_title(); echo "&lt;/a&gt;"; echo "&lt;/span&gt;"; echo '&lt;/li&gt;'; endif; } echo '&lt;/ul&gt;'; } else { // no posts found } endif; ?&gt; </code></pre> <p>So it's not perfect...if anyone have a proper solution, Thank you</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload