Support

Account

Home Forums General Issues Simply query using a sub field as the meta_key

Helping

Simply query using a sub field as the meta_key

  • This is my first go at querying based on ACF and I’m hitting a little mental snag. I have a custom post type set up with a bunch of fields using ACF pro. I want to be able to query on a sub field. Not within a repeater, just a subfield. Here is the structure:

    event post_type
    date_time
    start_date (set with picker and stored as mm/dd/yyyy)

    Here is what I would assume would work if I wanted to find all all events with a start date of today or later, but it doesn’t work.

    $args = array(
    ‘post_type’ => ‘event’,
    ‘meta_key’ => ‘date_time_%_start_date’,
    ‘value’ => date(‘mmddyyy’),
    ‘type’ => ‘DATE’,
    ‘compare’ => ‘>=’
    );

    I’m sure I’m missing something simple. I have a couple other straightforward queries that need to be structured as well. One problem (maybe) is that all my fields are structured like_this and I don’t know if the multiple underscores will throw off a sub field search.

    Thanks for the help with a new guy, I appreciate it.

  • You guys can close this, it was all me and a misunderstanding of how meta-keys are setup. All good now searching: meta_key => date_time_start_date

    Sorry for clogging the forum with this.

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

The topic ‘Simply query using a sub field as the meta_key’ is closed to new replies.