Support

Account

Home Forums Front-end Issues Query from radio button field not working

Solved

Query from radio button field not working

  • Hi,

    I’ve set up a radio field for a custom post type called Column. The 2 values you can select are left and right.

    I have this query working:

    <?php
        $args = array(
          'numberposts'	=> -1,
          'post_type'		=> 'work',
          'meta_query' => array(
              array(
                  'key' => 'column',
                  'value' => 'left'
              )
          )
        );
    
        $the_query = new WP_Query( $args );
    
        ?>
        <?php if( $the_query->have_posts() ): ?>
          <ul>
            <?php while( $the_query->have_posts() ) : $the_query->the_post();
    
            $workColor = get_field('work_colour');
    
            ?>
            <li class="block" style="background-color: <?php echo $workColor; ?>;">
              <a href="<?php the_permalink(); ?>" data-color="<?php echo $workColor; ?>">
                <div class="inner">
                  <img src="http://duo.local/wp-content/uploads/2017/10/nsconcrete.jpg" alt="">
                </div>
              </a>
            </li>
          <?php endwhile; ?>
        </ul>
      <?php endif; ?>
    
      <?php wp_reset_query(); ?>

    This query is working and only showing the posts that are ‘left’ selected.

    When I change the meta value from ‘left’ to ‘right’ it doesn’t show anything yet there are posts that are selected with right.

    
        'meta_query' => array(
            array(
                'key' => 'column',
                'value' => 'left'
            )
        )

    Any help with this would be greatly appreciated.

    Thanks

  • Does anybody have any suggestions?

  • There is only one thing I can think of that would cause it to work for left and not right and that is that the value being saved is not “right”. The first thing I’d do is double check the values I’ve set up for the radio field.

  • Haha jesus. Typical typo in the backend. It was:

    right:: Right instead of right : Right

    I did set this up on the last day of the working year after a few beers. Thanks John.

Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘Query from radio button field not working’ is closed to new replies.