Skip Navigation

[Resolved] Custom post counter

This support ticket is created 7 years, 10 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.

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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 4 replies, has 2 voices.

Last updated by Beda 7 years, 10 months ago.

Assisted by: Beda.

Author
Posts
#402387

I am trying to:

I have created a custom post type called ' postcards. I have been trying to display the postcard number ( assuming the 1st posted postcard would become nr 1; 2nd postcard nr 2 ;3rdpostcard nr 3 etc.) without any sucess. Is this possible at all to achive with views?

#402415

Could this be used to resolve my problem? Tried to implement, but doesnt seem to work with my custom post:

function updateNumbers() {
/* numbering the published posts: preparation: create an array with the ID in sequence of publication date, /
/ save the number in custom field 'incr_number' of post with ID /
/ to show in post (within the loop) use <?php echo get_post_meta($post->ID,'incr_number',true); ?>
/ alchymyth 2010 */
global $wpdb;
$querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post' ";
$pageposts = $wpdb->get_results($querystr, OBJECT);
$counts = 0 ;
if ($pageposts):
foreach ($pageposts as $post):
setup_postdata($post);
$counts++;
add_post_meta($post->ID, 'incr_number', $counts, true);
update_post_meta($post->ID, 'incr_number', $counts);
endforeach;
endif;
}
add_action ( 'publish_post', 'updateNumbers' );
add_action ( 'deleted_post', 'updateNumbers' );
add_action ( 'edit_post', 'updateNumbers' );

<?php echo get_post_meta($post->ID,'incr_number',true); ?>

#402466

I am not sure how you want to display this content.

In a View, you will have Lists of those Postcards.

You can easily display a number next to them by using HTML ordered lists.
hidden link

You would wrap the content of your Postcard that you display in the View Loop with the above HTML.

I can not help with the DataBase Query you try to build above; this is not related to Toolset API.
https://toolset.com/toolset-support-policy/

Can you instead elaborate exactly how you want to show your data, maybe the solution is much easier, and we can come up with a GUI-only solution?

#402554

Probably it would be easier if you have a look at the actual page, here is a link to one of the postcards, you will see that the postcard is numbered {it is hard-coded at the moment as i have not found a way of auto numbering the postcards and then have that number printed automatically it}:

hidden link

hope this helps

#402633

Well, one easy solution would be using the Page number instead of a hardcoded one, since you display only one postcard per page.
Youz could use the ShortCode [wpv-pager-current-page]
https://toolset.com/documentation/views-shortcodes/#wpv-pager-current-page

But that would only work in the Paginated View, not on the single Postcard template.

I assume you also would like the number when viewing a single Postcard?

This isn't possible with Toolset.

You would need Custom Code, which is above the scope of Toolset and it's technical support.
https://toolset.com/toolset-support-policy/
This here is a Stackoverflow Post that will help you achieve the goal:
http://stackoverflow.com/questions/19303556/wordpress-loop-how-to-count-items

You would need to populate a field ion your Post with that number or create a ShortCode that does display the value for you

You could also use a Custom Field instead, where you enter it manually.

I apologise that this goes above the scope of Toolset.

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