Skip Navigation

[Resolved] query custom post category

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
- 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 7 replies, has 3 voices.

Last updated by Minesh 2 years ago.

Assisted by: Minesh.

Author
Posts
#2313063

Dear Sir/Madam,

I have a Toolset custom post type with many categories, I want to create a snippet code to count the number of each category and put it to View, how can I do that?

#2313257

Nigel
Supporter

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

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

Hi there

Can you clarify what you are trying to output?

You want to display all of the categories and show how many posts each category is assigned to?

Or something else?

#2313765

Dear Nigel,

Yes, I want to display all of the categories and show how man posts each category is assigned to, especially those categories belong to the custom post type.

Best regards,

Kelvin.

#2313903

Minesh
Supporter

Languages: English (English )

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

For instance lets say, you have post namely "Test post" and you assigned terms movie, chess and music to it. Now, when you display "Test post" on frontend - you want to display terms movie, chess and music with count - is that correct? if yes:

Are you using blocks to build your content template or view?

#2314339

Dear Minesh

I need a shortcode and I can put in View, is there any API for this?

#2316113

Minesh
Supporter

Languages: English (English )

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

What if you try to use the following shortcode: wpv-post-taxonomy
=> https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-153472

For example:

[wpv-post-taxonomy type="gym-type" format="count"]

Does this helps?

#2321457

Dear Minesh,

Shall I have the PHP code having the result to this shortcode, so that I can add some more custom WHERE condition?

#2322655

Minesh
Supporter

Languages: English (English )

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

The shortcode [wpv-post-taxonomy] is using WordPress function get_the_terms to query terms:
=> https://developer.wordpress.org/reference/functions/get_the_terms/

In your case, I suggest to use the default standard WordPress function: wp_get_object_terms() to get the terms assigned to post:
=>https://developer.wordpress.org/reference/functions/wp_get_object_terms/

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