• Alright, I’m a bit stumped. I’ve tried every solution I find, and I can’t get this loop to work.

    I’m running Jupiter Theme from Artbees, and I’ve created custom post types and custom fields via wp-types plugin with slugs as follows:
    A Custom Post Type: “event_date”
    A custom Field: “event_type”
    An Option for the “event_type” field (via drop-down selector): “mastering_memory” (among other options they can pick for the same field)

    I’m attempting to create a loop that will display all “event_date” posts that have an “event_type” field with a value of “mastering_memory”

    Additionally I would like to sort by another custom field: “date” – but that’s not as urgent as just getting this loop working.

    Among many attempts, I currently have the code below.
    I’ve searched extensively but nothing seems to produce results. This code is the closest I’ve gotten, and simply displays the “There are no dates to display.” message. My PHP skills are very limited, so apologies if this is a simple fix that I just don’t grasp (yet).
    I thank you for your help and suggestions!!
    `
    <?php
    // Set arguments for the query in a php array.
    $args = array(
    ‘post_type’ => ‘event_date’,
    ‘meta_key’ => ‘event_type’,
    ‘meta_value’ => ‘mastering_memory’);

    $query = new wp_query( $args );

    //While you still have posts (haven’t displayed the last one) – then display it!
    if ( $query -> have_posts() ) : while ( $query -> have_posts() ) : $query -> the_post();

    ?>

    <div> // display resuts here (this part works fine, so removed)</div>

    <?php
    endwhile;
    //pagination controls here (I think)
    else:
    ?>

    <p>There are no dates to display.</p>

    <?php endif; ?>
    `

Viewing 1 replies (of 1 total)
  • Thread Starter theamazingaustin

    (@theamazingaustin)

    Would this question be more appropriate for the ‘hacks’ forum?
    I guess there is no way for me to remove or relocate this topic…?

Viewing 1 replies (of 1 total)
  • The topic ‘Creating a loop that displays custom post type with matching field?’ is closed to new replies.