Skip Navigation

[Resolved] I want to only display the parent items of the current user in a select box

This support ticket is created 6 years, 10 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Author
Posts
#621192
Screen Shot 2018-03-02 at 12.38.05 pm.png

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

#621288

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Razvan

As you probably know we are nearing completion on an overhaul of post relationships and released the first version of a new API as part of that process yesterday (https://toolset.com/2018/03/how-to-prepare-your-sites-for-the-new-post-relationships-coming-in-types-2-3/).

It is possible that custom code that works now will need changing, so I'm consulting with the developers about best practices about this particular issue before I give you any advice which could change in a matter of weeks.

(I'm also pushing a non-code solution for this, but I don't know yet whether we might have that in time for the relationship switch over.)

I'll be in touch as soon as I am confident about the advice I give you.

#622865

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Razvan

I haven't forgotten about you. I've spoken with the developers a couple of times and they have asked for a little time to complete some work before making any recommendation.

Thanks for your patience.

#627169

Hi Nigel,

Thanks a lot for the follow-up! Any updates?

Thanks!
Razvan

#627707

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Sorry, not yet!

We are entering the final stages of preparing for a stable release, so I should be able to get some more clear advice from the developers.

I have a meeting with them Monday morning and I'm adding a note for myself to bring this up again with them then.

Thanks for your patience.

#628587

Thanks Nigel!

#628685

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

OK, so work on this is underway.

For CRED you won't need any custom code, there will be an attribute available in the CRED field for the parent post selector.

I'm sorry you'll have to wait a bit longer, but you will get an in-built solution that doesn't require any custom code.

It will appear in the release candidates for the final plugin versions with the post relationships updates, it probably won't make it into any prior betas. The RCs are due within weeks.