Skip Navigation

[Gelöst] count

This support ticket is created vor 7 Jahre, 3 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.

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 4 Antworten, has 2 Stimmen.

Last updated by triggeru571 vor 7 Jahre, 3 Monate.

Assisted by: Minesh.

Author
Artikel
#471514
Screen Shot 2016-12-28 at 7.59.06 PM.png

I am trying to display a custom taxonomy count for ONLY the child posts. This is what I have

Parent Posts
Each parent post has its own child posts.
Each child post has 3 taxonomies

I want the parent post to display a count of taxonomies in its children only.

Currently I am getting a full count of all the taxonomies of all the child posts.

Setup:

1 Content Template which displays the Parent Post.

Within it I have a VIEW as follows:

Content Selection - Payment Reports (the child posts)
Query Filter: Select posts that are children of the Post where this View is shown.
Limit and Offset: 1
Loop output editor:

[wpv-layout-start]
	[wpv-items-found]
	<!-- wpv-loop-start -->
		<wpv-loop>
          [wpv-view name="payment-status-taxonomy"]
        </wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

The above has this view in it:

Name: Post Status Taxonomy.

Content Selection: Taxonomy > Payment Statuses
Query Options: Include terms that have non-empty descendants, Include children in the post count
Limit: None
Query filters: None

Loop Output Editor

[wpv-layout-start]
	[wpv-items-found]
<!-- wpv-loop-start -->

	<wpv-loop>
 [wpv-post-body view_template="Loop item in Payment Status"]     
	</wpv-loop>
	<!-- wpv-loop-end -->
	[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

Templates for this View

<span class="badge [wpv-taxonomy-slug]">[wpv-taxonomy-post-count] </span>

As you can see from the screenshot attached, I get an output of 2 Green, 1 Red, 2 Orange but this is wrong. It is picking up the count of taxonomy from another post. It should display: 2 Green, 1 Red, 1 Orange.

Any help would be greatly appreciated.

#471706

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

[wpv-taxonomy-post-count] shortcode will output the number of posts for the current taxonomy inside a taxonomy view loop.
=> https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-taxonomy-post-count

To get child post count, you need to use following code:

$childargs = array(
'post_type' => 'room',
'numberposts' => -1,
'meta_query' => array(array('key' => '_wpcf_belongs_property_id', 'value' => get_the_ID()))
);
$child_posts = get_posts($childargs);
$total = count($child_posts);

You can convernt above code in to shortcode and return the $total to dispaly the count of child posts.

More info:
=> https://toolset.com/documentation/user-guides/querying-and-displaying-child-posts/

#471812

Thank, but the above code will only output the number of child posts. I need to render at least the number of child posts for a particular taxonomy. The count of child posts have to be specific for the parent as per the description and image above.

#471814

Can we count values in a custom field and display that?

For example I could create a custom field with the 3 options with value of 1 if selected and 0 for not selected.

I would then need a code which will count each of the values separately for the children.

Which option is easiest and better for performance?

#471861

Fixed! I created 3 CPT as child posts, did away with the taxonomy then filtered using views and added the short code [wpv-found-count]

Works perfectly and a much more organized solution 🙂

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.