0

Scenario:

I have a custom post type with custom meta boxes. Each post should represent a row in my table i.e

Activity 1 Jan, Activity 1 Feb and Activity 1 Mar

I have a custom taxonomy of terms for my Activity types:

Activity 1,  Activity 2 and Activity 3.

I am using

archive-custom-post.php

to list my custom taxonomy term links, and

taxonomy-custom.php

to show each Activity time table.

Edit: Further clarity.

My question is - how do I query the meta data of all posts associated with Activity 1 term type? I am able to query the current post with get_post_custom but that is not enough. Should I be looking at WP_Query?

Edit: Activity data example.

  • Start and end date.
  • Duration
  • Cost
  • Paypal button

Thanks

2
  • Could you maybe provide an simple example of actual data? I have trouble following the part about "associated" meta data.
    – Rarst
    Commented Mar 10, 2014 at 21:08
  • Yes, I have made two edits which I hope helps to clarify what I am trying to do? Commented Mar 10, 2014 at 21:21

1 Answer 1

0

This is my own solution, improvements welcome :)

Check for term ID and assign to variable.

$term_id = (has_term('activity_1','activity-tax') ? 1 : (has_term('activity_2','activity-tax') ? 2 : (has_term('activity_3','activity-tax') ? 3 : '')));

Use term ID variable in my get_posts parameters.

$args = array(
'post_type' => 'activity-post',
'order' => 'ASC',
'tax_query' => array(
    array(
    'taxonomy' => 'activity-tax', 
    'field' => 'term_id', 
    'terms' => $term_id) // Only the ID I want
)
); 
$posts = get_posts($args);

Run over each post and create a Multiple Array of Meta Data.

$custom_post = array();
foreach ($posts as $post) {
    $custom_post[] = get_post_custom($post->ID);
}

Finally get the array's meta data I want.

foreach ( $custom_post as $key => $value ) {
    echo $value['date'][0].'<br />';
    echo $value['duration'][0].'<br />';
    echo $value['paypal'][0];
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.