Skip Navigation

[Resolved] Autofill field with number of children

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.

Tagged: 

This topic contains 1 reply, has 1 voice.

Last updated by dianaM-4 5 years, 6 months ago.

Author
Posts
#375903

I am trying to: Auto fill a custom field in my CRED-Form with the number of children of the parent post (number of brothers) .

I have a parent view "frageforum", where all my related children "frage-antwort" (= user-questions) are listed. I putted a CRED-form into the same view, so that users can send new questions. I want to autofill a field in the CRED-form with the ongoing number of question.

I created a parametric-search-view, with filter by parent view, where I only put in the [wpv-items-count] as the output field. And created a content view "counter" with the parametric-search-view. Till here everything's good. If I place my "counter"-content-view anywhere in my output view "frageforum", it shows me the right number of children.

Now in CRED, I wanted to bring in the view as a value of a field. Like this:

[cred_field field='frage-nummer' post='frage-antwort' value='[wpv-post-body view_template="auslobung-frageforum-single-counter" id="$frageforum"]' urlparam='' readonly="true"]

But the view doesn't show only the number. Unfortunately the number is surrounded by a div.

<div id="wpv-view-layout-292-CPID287" class="js-wpv-view-layout js-wpv-layout-responsive" data-viewnumber="292-CPID287" data-pagination="{"ajax":"false","effect":"fade","duration":500,"stop_rollover":"false","cache_pages":true,"preload_pages":true,"pre_reach":1,"spinner":"default","spinner_image":"<em><u>hidden link</u></em>","callback_next":"","manage_history":"on","has_controls_in_form":"off","max_pages":0,"page":1}" data-pagepermalink="/nexttest/frageforum/510-frageforum/?wpv_view_count=292-CPID287&wpv_paged=1">								3		</div>

Is there a way, to put in only the displayed number?
Or another way, to put the number of brother posts into a custom field of my CRED-form?

I found this post for implementing the parent ID:
https://toolset.com/forums/topic/auto-fill-parent-field-in-cred-form/page/2/
Is there a similar way to display the children-number of the parent ID?

Thanks for your help!

#375914

Sorry, I found another way by myself.
I figured out, that the view didn't fit my need. So I added a new shortcode for the post-number. Here my result, for those who may need it:

add_shortcode('current-nr', 'current_nr_func');
function current_nr_func($atts, $content){
    $queried_object = get_queried_object();
    $parenttitle = get_the_title($queried_object);
    // searching for children
    $query = array(
        'post_type' => 'THE-SEARCHING_POSTTYPE',
        'post_parent' => $parenttitle,
        'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'private'),
        'numberposts' => -1
    );
    $mynr = count( get_posts( $query ) );
    return $mynr;
}