Skip Navigation

[Resolved] total count and total displayed

This support ticket is created 3 years, 8 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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Karachi (GMT+05:00)

This topic contains 6 replies, has 2 voices.

Last updated by AlimB3245 3 years, 8 months ago.

Assisted by: Waqar.

Author
Posts
#1724925

Tell us what you are trying to do? I am trying to show the user the TOTAL that exists for the posts (ALL POSTS) and show them how many are being displayed.. so I am using this.. [wpv-items-count] of [wpv-found-count] .. I am not using pagination.. but even if I were to use pagination, I would like one of the figures to be the total posts that the application has and should have nothing to do with what's being queried or displayed... So if I had 1000 products and a user were to filter the view and show 10 of them it should show as 10 of 1000 and if the pagination were on which shows 50 products per page then it should show 50 of 1000 and if I were to use a filter that showed just 4 from all the posts it should show 4 of 1000.. but I can't seem to manage this..

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?hidden link and

#1725627

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

If your goal is to show the count of total available posts in a way that it doesn't get affected by the current view's query (i.e. search/query filters or pagination), you can create a duplicate of your view and set this new view to show all posts without any pagination or search/query filters.

The loop item content of this new view will be empty and outside the loop, it will just include the "wpv-found-count" shortcode, to show the count of all available posts.

I hope this helps and please let me know if you need any further assistance around this.

regards,
Waqar

#1726425

Hi Waqar

Thanks for the update..:-)...

Theoretically I have understood your response.. but not sure how to implement it..

I have added a new page and created a view called as 'Total Opticians' and have disable all pagination etc.. now in the my Content Template how do I use the [wpv-found-count].. if I do use this short code, do I not have to define the view?

I am in an Archive Template for Opticians and I am assuming if I use the [wpv-found-count] variable it would still get affected by the Archive Template view.. no?

Please do let me know if I am missing something here..

Another question would be would I have to create a separate view for each custom post type if I needed all the totals or could I create one view and select all the custom posts I wanted in the view and then when I user the [wpv-found-count] variable I could filter it to the custom post type I was referring to.. is that possible? or I have to create a view for every custom post type separately?

Regards,
Alim

#1726463

[wpv-found-count view-template="Total Opticians"]

is this what I need to do? I tried it but it didn't seem to work..

Regards,
Alim

#1728137

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Alim,

Thanks for writing back.

The shortcode "wpv-found-count" doesn't accept any attribute, as mentioned in its documentation:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-found-count

Technically, it should return only the count of results items from a view in which it is directly placed and shouldn't be affected by parent view or archive.

Can you please share temporary admin login details, so that I can see exactly how and where you've added this new view?

I'll be in a better position to guide you about the missing link, accordingly.

Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.

regards,
Waqar

#1730767

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Alim,

Thank you for sharing the admin access.

I've performed some tests on my website and this custom shortcode can be used to show the count of published posts, on the post type archive page.
( in a way that it is not affected by the pagination or search filters )


add_shortcode('get_post_count', 'get_post_count_func');
function get_post_count_func($atts) {

	$a = shortcode_atts( array(
		'type' => '',
	), $atts );

	if(!empty($a['type'])) {
		$post_type = $a['type'];
		$post_count_obg = wp_count_posts($post_type);
		$post_count = $post_count_obg->publish;

		return $post_count;
	}
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through active theme's "functions.php" file.

After that, you can replace the [wpv-found-count] shortcode with this new shortcode:


[get_post_count type="optician"]

On the archive for the other post types, you can just replace "optician" with that post type's slug and it will show the count of its posts.

And to show the count of instances of a repeating custom field, you can register another custom shortcode, as explained in this reply:
https://toolset.com/forums/topic/conditional-on-amount-of-repeatable-fields/#post-1389441

regards,
Waqar

#1732729

My issue is resolved now. Thank you!

Thanks Waqar.. it worked perfect..:-).. will try your link for the repeating custom field later..

Have a nice day..:-)..

Regards,
Alim

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