Problem:
How to show parent posts in the CRED parent Picker field, that are authored by the current logged in user only
Solution:
1. A "Create [child] Post Form"
2. In the Parent Selector Code of that form you should use only default available arguments, as this:
<div class="cred-group cred-group-parents"> <div class="cred-field cred-field-_wpcf_belongs_page_id">//change "page" to your parent post slug <label class="cred-label"> Choose Parent </label> This is only for test display: [get-parents] [cred_field field='_wpcf_belongs_page_id' value='']//change "page" to your Parent Post Slug </div> </div>
3. In the JS:
jQuery('document').ready(function(){ var post_parents = jQuery('#parents_id').val(); var arr = post_parents.split(','); jQuery("[name=_wpcf_belongs_page_id] > option").each(function() { //change "page" to your parent post slug var option_val = jQuery(this).val(); if( jQuery.inArray(option_val, arr) == -1 && option_val != -1 ){ jQuery(this).remove(); } }); });
4. In functions.php:
function get_parents($atts) { global $current_user; get_currentuserinfo(); $author_query = array('post_type' => 'page', 'posts_per_page' => '-1','author' => $current_user->ID,); $author_posts = new WP_Query($author_query); $parent_ids = ""; while($author_posts->have_posts()) : $author_posts->the_post(); $parent_ids .= get_the_ID() .","; endwhile; return $parent_ids; } add_shortcode('get-parents', 'get_parents');
5. in Views > Compatibility > 3rd party ShortCodes register:
get-parents
6. If you insert the CRED Form in a Post, it correctly displays only parent Posts of current author/user.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | - | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 | 14:00 – 20:00 |
- | - | - | - | - | - | - |
Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)
This topic contains 2 replies, has 2 voices.
Last updated by 7 years, 1 month ago.
Assisted by: Beda.