Hi Guys,
I followed all the steps described here https://toolset.com/forums/topic/i-want-to-only-display-the-parent-items-of-the-current-user-in-a-select-box-2/, but I still have the full list of post instead of just author's posts.
Is the structure or function of the fields changed since the last post? Could you please help?
Please find below the 3 blocks of code that I'm using:
<div class="cred-group cred-group-parents">
<div class="cred-field cred-field-_wpcf_belongs_site_id">
<label class="cred-label">
Choose Parent
</label>
<input type="hidden" id="parents_id" value="[get-parents]" /> This is only for test display: [get-parents]
[cred_field field='_wpcf_belongs_site_id' value='']
</div>
</div>
-----------------------------------------------------------
jQuery('document').ready(function(){
var post_parents = jQuery('#parents_id').val();
var arr = post_parents.split(',');
jQuery("[name=_wpcf_belongs_site_id] > option").each(function() {
var option_val = jQuery(this).val();
if( jQuery.inArray(option_val, arr) == -1 && option_val != -1 ){
jQuery(this).remove();
}
});
});
-----------------------------------------------------------
function get_parents($atts) {
global $current_user;
get_currentuserinfo();
$author_query = array('post_type' => 'site', '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');
-----------------------------------------------------------
What is the link to your site?
hidden link