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?
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); ?>
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?
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
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.