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 - 661 through 675 (of 711 total)
Problem:
How to output relationship fields when displaying one of the relationship post types in a View?
Solution:
When you output the field using a types shortcode it needs to include an item attribute that specifies that the post source if the intermediate post type where the relationship fields are stored, like so:
Using the Fields and Views button to insert the field—and specifying the source in the Post Selection tab—will ensure the correct format for the shortcode.
Problem: I would like to give my site visitors the ability to use a checkbox in a custom search View that filters based on whether or not the post has child posts.
Solution: This filter is not built-in to Views, but you can set up a custom field on the parent post type that stores a 1 if child posts exists and stores nothing if no child posts exist. That custom field value can be managed automatically with code.
add_action( 'toolset_association_created', 'toolset_number_child_posts', 10, 5 );
add_action( 'toolset_before_association_delete', 'toolset_number_child_posts', 10, 5 );
function toolset_number_child_posts( $relationship_slug, $parent_id, $child_id, $intermediary_id, $association_uid ) {
// add a 1 if child properties exist to facilitate filtering by existence of child post
if( get_post_type($parent_id)=='developments' ) {
// get most recent property post
$property_args = array(
'numberposts' => 1,
'post_type' => 'property',
'orderby' => 'post_date',
'order' => 'DESC',
'toolset_relationships' => array(
'role' => 'child',
'related_to' => $parent_id,
'relationship' => 'developments_property'
),
);
$properties_query = new WP_Query( $property_args );
$properties = $properties_query->posts;
if(isset($properties[0])) {
// set the checkbox custom field value here using update_post_meta
update_post_meta( $parent_id, 'wpcf-has-vacant-properties', 1);
}else {
delete_post_meta( $parent_id, 'wpcf-has-vacant-properties');
}
}
}
function toolset_count_child_properties_on_save( $post_id ) {
if( get_post_type( $post_id ) == 'developments' ) {
toolset_number_child_posts( 'developments_property', $post_id, null, null, null );
}
}
add_action( 'save_post', 'toolset_count_child_properties_on_save', 1000);
Problem: I have a Repeating Field Group (RFG) assigned to a custom post type called "Projects". I would like to use Views to show a custom field from the first RFG in each Project.
Solution: Use the "limit" setting in the View editor screen to limit the number of results that will be displayed in the View of RFGs, and use sorting to determine which RFG will be displayed.