This support ticket is created vor 7 Jahre, 6 Monate. 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.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
I created a parent / child relationship between the content type "Stock" (father) and the content type "Issue" (child). The Stocks have products.
The users can create issues with a CRED form, related with their product through the select relationship field. Currently it shows all the items from the father, but I need to filter this result, showing only those corresponding to the user logged.
Yes, I need to filter these posts but inside the select field who displays the relationship. In this form it's named 'Assigned resources'
I do not know if I'm explaining well.
Yes, this is why we're working in an reporting system where the users can send us notifications by e-mail about a problem with their equipment. To make it more ease for the user, we need to display only the equipment assigned to him in the select field.
Is it possible?
Thank you in advance.
It would require some custom coding in order to achieve. Such custom coding is out of the scope of our support forum.
However you can get further assistance on this by contacting one of our certified consultants by going to the link below. https://toolset.com/consultant/
Now, I want to display these results (JSON) inside the select field. I am using this code but it doesn't work, the select field don't appears on the screen:
Can you create a testing page and send me the link ?
On that testing page I need for you to add this view to it [wpv-view name="items-in-selection-when-creating-an-issue" users='[wpv-current-user info="id"]']
I want to see if the html divs are rendered around the view.
We actually have a custom solution for this 🙂 however we won't be able to provide much debugging on this since its custom code.
Add the following to your CRED form.
<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>
<input type="hidden" id="parents_id" value="[get-parents]" /> 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>
Add this to the js editor of your CRED form.
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();
}
});
});
function get_parents($atts) {
global $current_user;
get_currentuserinfo();
$author_query = array('post_type' => 'page', 'posts_per_page' => '-1','author' => $current_user->ID,); //change page to your parent post slug
$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');
Add that to your functions.php file.
This should display the parent posts for the current user in your CRED form.
Hello Shane, thank you very much for your help, We're very thankful.
The code works correctly, except for the tag [get-parents] indicated in the value of the input field. For some reason it is not executing it and the value returns the tag as it is.
If we insert the id's manually, separated by commas, the select shows the results.