Skip Navigation

[Resolved] Getting the ID for an child post

This support ticket is created 3 years, 11 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
- 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 3 replies, has 2 voices.

Last updated by Minesh 3 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1631211

Tell us what you are trying to do?

Hi, I have a parent post type called a "fair" and each fair has many children posts called "booths". I am trying get the number of the child (number of the first booth created would be 1, the number of the second booth created would be 2, etc). The reason I want this I want to display this number in the booth post content template. This means that the booth that was created first would be displayed as "booth 1" and the booth that was created 20th would be "booth 20". However, even though it seems that Toolset seems to store the list of booths for a career fair and I can display this list via views, I do not know how to get the number of the booth.

Is there any documentation that you are following?

I found this topic here: https://toolset.com/forums/topic/auto-incrementing-id/
That seems very similar. This user seems to be trying to get a custom field value and automatically increment it. It seems like I could have a custom field name "booth number" and automatically increment it for each booth to assign them a number, but it seems like this type of number might already be available in Toolset. Also, I am not familiar with editing my theme/php file so I am not sure how to do it in this approach.

What is the link to your site?
hidden link

This is a link to test career fair with different employer "booths".

#1631425

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Views offer the shortcode [wpv-loop-index] using which you can output the current loop index within the view:
=> https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-loop-index

If you are displaying your posts using views, then you can use the shortcode:

[wpv-loop-index accumulate="true" pad="false" offset="0"]

Please note that the above shortcode will output the loop index, not any other number, if you want to display a stored number, I think that might be the better approach to number your booths. You should create a "booth number" field and as you said, when you save your post, you should automatically increment the number to it but if the above option works for you then you can go with that.

#1637871
within booth.png
index of loop in booth.PNG

This is is very helpful as this allows me to to display the booth number in the view.

However, I would also like to be able to display the booth number within the booth post, which I am not sure if it is possible with this approach. I will need that number for a variety of things, such as directing users to a url as well (mysite/booth1.com). Is there a way to display this within the actual post as well?

#1638283

Minesh
Supporter

Languages: English (English )

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

As I shared the information regarding the [wpv-loop-index] shortcode that the number will be generated by the shortcode [wpv-loop-index] and it will work within the view only. In this case the Booth number is not attached to post but its exclusively generated by the View.
=> https://toolset.com/documentation/user-guides/views/views-shortcodes/#wpv-loop-index

I suggest the better approach would be, you should add a custom field to your booth post that holds the booth id.

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