WordPress.org

Support

Support » Plugins and Hacks » [Resolved] [Plugin: Simple Fields] Compare fields between posts

[Resolved] [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/

Viewing 1 replies (of 1 total)
  • 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 ‘[Resolved] [Plugin: Simple Fields] Compare fields between posts’ is closed to new replies.