Views is a WordPress plugin that lets you display post relationships.
In our user guides, you can find more information on how to display child posts, related posts, brother pages, fields of parents and fields of grandparents.
When you ask for help or report issues, make sure to tell us the type of the relationship you are trying to build and the structure of your data.
Viewing 15 topics - 841 through 855 (of 1,097 total)
Problem: I have two Views of taxonomy terms, shown as tabs and tab panels, in a tab-based interface that allows users to select a term and show the associated term panel. This tab interface is displayed in a parent post type. In the tab panel of each term I include another View that shows all the child posts associated with that term. If no child posts are found, I do not want to show the tab or tab panel.
Solution: There's not a good way to apply conditional logic to a parent View that tests the output of a child View. Instead, you must apply a taxonomy query filter with the following custom code. This code loops over all the child posts associated with the current parent post, and builds an array of all the associated terms. If a term is not associated with any child, it will not be added. Then apply this as the "include" option in your taxonomy query as shown here:
add_filter( 'wpv_filter_taxonomy_query', 'prefix_only_assigned_tax_query', 10, 3 );
function prefix_only_assigned_tax_query( $tax_query_settings, $view_settings, $view_id ) {
global $post;
$views = [243391, 243393];
if( in_array( $view_id, $views) ) {
// query all credit posts and build an array of used cred-type terms
$ids = array();
$args = array(
'post_type' => 'credit',
'meta_query' => array(
array(
'key' => '_wpcf_belongs_website_id',
'value' => $post->ID
)
)
);
$ps = get_posts( $args );
foreach($ps as $post) {
// loop over each post and push its terms into the array
$terms = wp_get_post_terms( $post->ID, 'cred-type');
foreach($terms as $term) {
if( !isset( $ids[$term->term_id] ) ) {
$ids = array_merge($ids, array($term->term_id));
}
}
}
$ids = count($ids) ? $ids : array(9999999);
$tax_query_settings["include"] = $ids;
}
return $tax_query_settings;
}
Problem: I have a nested View setup where pagination occurs on the outermost View. When I navigate back and forth through the paginated results and return to the first page, some results are no longer found on my inner Views.
Solution: First Month View - uncheck "Don't include current page in query result"
Last Month View - uncheck "Don't include current page in query result"
Loop item in Home Agenda Events - add cached="off" to both First and Last Month View shortcodes.
Problem:
How do I query data from Parent posts into Views being generated by Child posts?
I’m still trying to figure out how to display Product URL data conditional on the Product parent of the current Excerpt child.
The View display logic is like this:
1) get the Product parent of the current Excerpt child.
2) get the Product URL children of that parent Product.
3) get the Retailer parents of those Product URL children.
4) combine data from these sources and display in the View.
Where and how in Toolset do I build this conditional logic?
Solution:
I would suggest to change the relation between your CPT as follows:
In your case, we need to get data in this way. Excerpt >> to Product >> then product to Product URL and Retailer as follows:
Excerpt >> Product >> Product URL + Retailer
So that we need to update relation like this.
ProductURL..............Retailer [ 2 parents ]
|..........|..............|
|.........Product [ 1 intermediate child of both Product URL & Retailer ]
…………|
…….Excerpt [ 1 child of Product ]
- Then on Excerpt View1 we can get product data.
- And on Product View2 we can get Product URL and Retailer Data.
Alternatively, I suggest to make this setup bit less complex, so its easier for you to get and display Product URL, one way to do that is by adding ProductURL as custom field inside products or any other CPT, this way you will have one less CPT relation and it will most likely make it easier to display.
Problem:
Shortcode not displaying parent post ID, [wpv-post-id id="$product"] is not working.
Solution:
For some reason that shortcode was not working directly in Beaver Builder module. I have added that by inserting shortcode (for parent post ID) into a new Content Template >> and then inserted that Content Template into the page.
Problem: I would like to display some text and a custom field from a parent post within in my child post, but only if the child post has a parent post defined. If no parent is defined, I do not want to display anything here.
Solution: You can use the $parent-slug operator in a wpv-post-title or wpv-post-id shortcode to get information from a parent post type. If a parent of this post type is not defined, these fields are designed to fall back to display the child post. So, you can use a conditional that tests both IDs. If they are identical, then the parent is not defined. If they are different, then you know the parent is defined and the conditional is true.
[wpv‐conditional if="( '[wpv-post-id id='$client']' ne '[wpv-post-id]' )"]
[wpv-post-link id='$client']
[/wpv‐conditional]