Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9251479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:42:34+00:00 2026-06-18T10:42:34+00:00

I am querying a custom post type in an archive template. Each post has

  • 0

I am querying a custom post type in an archive template. Each post has meta values attached. The loop does list each post but the meta value on each post is pulling from the first post. So, I have a list of posts and all the meta values are the same, the data saved on the first post. The data is saved properly in the database. Here is my loop:

$current_time = current_time('mysql'); 
list( $today_year, $today_month, $today_day, $hour, $minute, $second ) = split( '([^0-9])', $current_time );
$current_timestamp = $today_year . $today_month . $today_day . $hour . $minute;


$args = array( 'post_type' => 'event',
'order' => 'ASC',
'orderby' => 'meta_value_num',
'posts_per_page' => 20,
'meta_key' => '_start_eventtimestamp',
'meta_query' => array(
    array(
        'key' => '_start_eventtimestamp',
        'value' => $current_timestamp,
        'compare' => '>'
    )
)
 );
// Gets the event start month from the meta field
$month = get_post_meta( $post->ID, '_start_month', true );
// Converts the month number to the month name
//$month = $wp_locale->get_month_abbrev( $wp_locale->get_month( $month ) );
// Gets the event start day
$day = get_post_meta( $post->ID, '_start_day', true );
// Gets the event start year
$year = get_post_meta( $post->ID, '_start_year', true );
$numdays = get_post_meta( $post->ID, '_tour_numdays', true );
$price = get_post_meta( $post->ID, '_tour_price', true );

query_posts( $args );

    while (have_posts() ) : the_post();
    echo '<ul>';
        echo '<li>' . $month . '/' . $day .'</li>';
        echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
        echo '<li>' . $numdays . '</li>';
        echo '<li>' . $price . '</li>';
        echo '<li><a href="#">Join this Trip</a></li>';
    echo '</ul>';
    endwhile;

I cannot find a solution. I have tried changing the query from WP_Query to query_posts but still no luck.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:42:36+00:00Added an answer on June 18, 2026 at 10:42 am

    Here’s your logic:

    Get Post Metas ($price, $month, etc.)
    
    Query Post (retuned an array of posts)
    
    Begin looping the array of posts
    
    Echo the results, including Post Metas ($price etc) which is NOT the metas of each post
    
    End loop
    

    You need to fetch the metas of each post by using get_post_meta() inside the loop.

    You’re currently doing:

    $month = get_post_meta( $post->ID, '_start_month', true );
    

    … $post->ID is NOT the ID of each post, only the first one.

    Here’s a sample of what the while() should look like (I’d better not provide an exact sample as I might missed something that could add to the confusion):

    while (have_posts() ) : the_post();
    
    $month = get_post_meta( $post->ID, '_start_month', true ); // here it is
    // $day = ... continue here
    
    echo '<ul>';
        echo '<li>' . $month . '/' . $day .'</li>';
        echo '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a></li>';
        echo '<li>' . $numdays . '</li>';
        echo '<li>' . $price . '</li>';
        echo '<li><a href="#">Join this Trip</a></li>';
    echo '</ul>';
    endwhile;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using a custom taxonomy and a custom post type: <?php function my_custom_taxonomies() {
I have a custom adapter that visualize each row in the list of Orders.
I want to use a custom class that could handle querying easily. Are there
I am working on a project that does a lot of querying and the
I'm using a custom ContentProvider . For querying, there is a CancellationSignal (API 16+)
I would like to be able to use custom string querying within my NHibernate
Basically I have a custom tag that handles querying a java object for me.
I'm querying the Google Books API, and I'm parsing the books into a custom
I have a custom filter for querying the database. The API layer build the
I am querying the terms in a custom taxonomy i have with the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.