php - Custom field value inside WP_Query -
i want wp_query, displays posts, have same custom field value display post.
this code:
function show_other_posts() { //get current custom field value if( get_field('desktop_cat') ){ $redirect_value = the_field('desktop_cat'); //echo current custom field value debugging echo $redirect_value; //query posts same value $redirect_args = array( 'posts_per_page' => -1, 'post_type' => 'post', 'meta_query' => array( array( 'key' => 'desktop_cat', 'value' => $redirect_value, 'compare' => '=' ) ) ); //display post titles $the_query = new wp_query ( $redirect_args ); if( $the_query->have_posts() ): while( $the_query->have_posts() ) : $the_query->the_post(); the_title(); endwhile;endif; wp_reset_query(); }; };
the problem must 'value' => $redirect_value,
because when enter value manually works well. there must problem variable.
any ideas?
thank much
the_field()
echoes field value. should use get_field()
instead (which returns, not echoes field value):
$redirect_value = get_field('desktop_cat');
Comments
Post a Comment