Support

Account

Home Forums General Issues Works for radio, not for checkbox

Solving

Works for radio, not for checkbox

  • Hi!

    So this is all pretty new to me. Struggling my way through code and all posted here already. Can anyone tell me, why this basic code does show how many time a radiobutton is selected, but when I use it on a checkbox, it will not display how many times that checkbox is selected. Should do that right, also for checkboxes?

    $args = array(
    ‘posts_per_page’ => -1, //get all posts
    ‘post_type’ => ‘project’, //posts, pages, whatever the field is attached to
    ‘meta_key’ => ‘project_status’, //custom field slug
    ‘meta_value’ => ‘Finished’ //location to count
    );

    // query
    $the_query = new WP_Query( $args ); //get WP Query using $args

    $count = $the_query->post_count; //use property post_count to return the count

    echo ‘Finished: ‘. $count;

  • The difference

    A radio field stores a single text value representing the value selected.

    A checkbox field stores an array of all of the values selected. This is stored as a serialized array in the DB

    When searching for posts with a specific checkbox selected you must search

    LIKE: '"YOUR VALUE HERE"'

  • I’ve seen examples before. Let me work on this. Thanks!!

    Remco

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

You must be logged in to reply to this topic.