Quantcast
Channel: Toolset » All Posts
Viewing all articles
Browse latest Browse all 20145

Adding fields data (parent post) to WP_Query

$
0
0

I'm probably going about this backwards but we'll see.

Right now I have a custom post type called "reviews", which is a sub-type of "Books" and is used for the author to reproduce his favorite Amazon reviews in their own tab on the book page.

Figure 1: The front end result
http://i.imgur.com/dFm5Uwj.png

At the moment, my query simply pulls all reviews, globally, without regards for which book they are attached to. Because Reviews are a child post type, they are linked to their parent via Field set (more on this in a moment):

Figure 2: The Parent Link
http://i.imgur.com/vOUb7uc.png

The review meta data is all contained within a custom field group called "Review Details"

Figure 3: Review Details
http://i.imgur.com/PM39VNd.png

So here's where things get mixed up. For the sake of ux design, I just called a WP Query like so:

$query = new WP_Query( array( 'post_type' => 'reviews', 'paged' => $paged, 'orderby' => 'meta_value wpcf-review-date', 'order' => 'DESC' ) );

This successfully pulls reviews into the reviews tab and I iterate over the custom meta data to get the result in Figure 1. The full loop looks like this:

http://pastebin.com/Qd0PViCX

Ok so we have established [a] the desired UI, [b] the configuration and [c][/c] the basic WP loop I am using. Now we get to what I need to learn.

I need to restrict the posts being pulled to the parent page assigned by the filed set in Figure 2 and I have no idea how to do that within the context of wp_query.

Help me Oby Wan Kenobi, you're my only hope!


Viewing all articles
Browse latest Browse all 20145

Trending Articles