Solution:
To filter the view result by parent, You will require to add a "Post relataionship" query filter from your "Query Filter" section of your view/block view and set the option "The post where the view is sown".
Problem: I would like to add a post owner filter to a View of a Repeatable Field Group (RFG). I am building this View in the Blocks editor, but I cannot see any way to add a dynamic filter based on the post being displayed.
Solution: Select the top-level View block using the Block Navigation menu, then you will find a Query Filter configuration panel in the right column of the Block Editor screen. You can add a post owner filter or any other Query Filter here. In an upcoming release of Views, you will be prompted to select this filter during the creation of the View. This improved workflow will help resolve this confusion.
Problem: I have two custom post types. On the template for CPT A, I would like to display two posts from CPT B in a View. In the post editor for CPT A, I would like to choose which two posts should be displayed in the View.
Solution: Use a many-to-many relationship between CPT A and CPT B to select which posts from CPT B should be displayed in each post of CPT A. Use a View of CPT B with a post relationship filter in the template for CPT A to display the selected posts.
Problem: I have a one-to-many relationship set up between two post types. In the child post single page, I would like to display a View of other sibling child posts.
Solution: This feature does not currently exist in Blocks, but in classic Views you can create a Query Filter for post relationship, where the parent post is set by a shortcode attribute "wpvrelatedto". Then you can provide the current post's parent post ID in the View shortcode as shown here:
Problem: I have a Form that edits posts, which includes a custom field. I would like to automatically set a taxonomy term on the post when the Form is submitted. The term should be determined by the value of the custom field.
Solution: Use the function wp_set_object_terms to set a term on a post:
Instead of term-slug you can use:
A single term slug, single term id, or array of either term slugs or ids. This will replace all existing related terms in this taxonomy. Passing an empty value will remove all related terms.
The last parameter false will delete all the other category terms from this post. If you use true instead of false, the existing category terms will not be deleted.
Problem: I have a custom role that should be able to submit a Form to add or edit a child post, but the parent post options are not shown in the select field in the Form. This was working before a recent update.
Solution: Check your custom code to confirm that redirects set up to block access to the back-end of the site are not applied to admin-ajax.php requests. Add some conditional logic to prevent those redirects as needed, like in the following code example:
/**
* Block wp-admin access for non-admins (not while doing AJAX, see https://toolset.com/forums/topic/custom-role-no-longer-able-to-perform-same-tasks/)
*/
function ace_block_wp_admin() {
if (!current_user_can('edit_users') && ( !defined('DOING_AJAX') || !DOING_AJAX ) ) {
wp_safe_redirect( '/my-account');
exit;
}
}
add_action( 'admin_init', 'ace_block_wp_admin' );