Title: [Plugin: Simple Fields] Compare fields between posts
Last modified: August 20, 2016

---

# [Plugin: Simple Fields] Compare fields between posts

 *  Resolved [sugardaddy](https://wordpress.org/support/users/sugardaddy/)
 * (@sugardaddy)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/plugin-simple-fields-compare-fields-between-posts/)
 * Actually I use the Custom Field Suite plugin to achieve that.
    But I prefer the
   flexibility of yours 😉 and the UI in the post admin. And I try to achieve what
   I did with CFS : display a random post in another one by fields comparison. That
   means I get the posts from a certain category which have a field value equal 
   to the same field of the current post. This is actually what I do :
 *     ```
       $product = simple_fields_get_post_value(get_the_id(), array(1, 1), true); // get the field value for "Produit associé"
                       global $post;
       				$args = array( 'numberposts' => 1, 'category' => 46, 'meta_query' => array( array( 'key' => 'Produit associé', 'value' => $product, 'compare' => '=' ) ), 'orderby' => 'rand' );
       				$usecases = get_posts( $args );
       				foreach( $usecases as $post ) :
       				setup_postdata($post);
       ```
   
 * But the combination of key and value doesn’t seem to work and, as you advice,
   I’d like to use IDs instead of names.
 * Thanks a lot for your help !
 * [http://wordpress.org/extend/plugins/simple-fields/](http://wordpress.org/extend/plugins/simple-fields/)

Viewing 1 replies (of 1 total)

 *  Thread Starter [sugardaddy](https://wordpress.org/support/users/sugardaddy/)
 * (@sugardaddy)
 * [13 years, 7 months ago](https://wordpress.org/support/topic/plugin-simple-fields-compare-fields-between-posts/#post-3088827)
 * I found the solution… and it’s a much reliable and easier way to achieve.
 * First I get the current value of the concerned field :
 * `$product = get_post_meta(get_the_id(), "_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0",
   true);`
 * Then I create a loop to browse my category and limited to the meta value found
   in the current post :
 * `$usecases = new WP_Query( 'cat=46&meta_value='.$product.'&orderby=rand' );`
 * Then I create my loop :
 * `while ( $usecases->have_posts() ) : $usecases->the_post();`
 * And finally, before the endwhile, I need to add a break to get only the first
   result :
 * `break; endwhile; wp_reset_postdata();`

Viewing 1 replies (of 1 total)

The topic ‘[Plugin: Simple Fields] Compare fields between posts’ is closed to new
replies.

 * ![](https://s.w.org/plugins/geopattern-icon/simple-fields_fafafa.svg)
 * [Simple Fields](https://wordpress.org/plugins/simple-fields/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/simple-fields/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/simple-fields/)
 * [Active Topics](https://wordpress.org/support/plugin/simple-fields/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/simple-fields/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/simple-fields/reviews/)

 * 1 reply
 * 1 participant
 * Last reply from: [sugardaddy](https://wordpress.org/support/users/sugardaddy/)
 * Last activity: [13 years, 7 months ago](https://wordpress.org/support/topic/plugin-simple-fields-compare-fields-between-posts/#post-3088827)
 * Status: resolved