Support

Account

Home Forums General Issues Query ACF values from a Taxonomy (with a twist)

Unread

Query ACF values from a Taxonomy (with a twist)

  • Hey Everyone,

    First time posting here. I’m essentially using ACF to create a ‘lazy’ client center that displays their order # price and shipping date. Their (post/client center) is simply a private page with an appended url that they are redirected to after they provide a login and password.

    So, what I would like to is run orders through a taxonomy (orders) of the client center
    and query the results based on a ACF field that is populated when they check out.

    So the query on the POST page would have an ACF with an ID
    And the taxonomies would be queried after filtering those that MATCH the ID field from Taxonomy>> Post

    Here is what I’ve got so far….

    —-begin—–

    <?php

    //I’ll get the ACF ‘ID’ field and save it to a variable

    $value = get_field( “id” );

    // Then query taxonomies ‘orders’ filtering the meta_key with the ACF ID ($value) of the Post

    $args = get_terms(array(

    ‘numberposts’ => -1,
    ‘taxonomy’ => ‘orders’,
    ‘meta_key’ => ‘accountid’,
    ‘meta_value’ => $value
    ));

    $the_query = new WP_Query( $args );

    ?>

    // Then display a table on the POST with the taxonomies that match the ID of the meta_key of the Post

    <?php if( $the_query->have_posts() ): ?>
    <table class=”table”>
    <thead>
    <tr>
    <tbody>
    <th scope=”col”>#</th>
    <th scope=”col”>Item</th>
    <th scope=”col”>Date Shipped</th>
    <th scope=”col”>Price</th>
    </tr>
    </thead>
    <?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <tr>
    <th scope=”row”>1</th>
    <td><?php the_field( ‘product_name’); ?></td>
    <td><?php the_field( ‘date_shipped’); ?></td>
    <td><?php the_field( ‘cost’); ?></td>
    </tr>
    <?php endwhile; ?>
    </tbody>
    </table>
    <?php endif; ?>

    <?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>

    —-end messy code

    Google console isn’t showing any data…so the error must be how the query is written (otherwise there would be a <table> with no data since it is before the loop.

    Your assistance/guidance is appreciated

    —-Dan

Viewing 1 post (of 1 total)

The topic ‘Query ACF values from a Taxonomy (with a twist)’ is closed to new replies.