Problem:
The problem here is that the user is using the wpv-after-display-post hook in order to do a views counter on his post. This means that the counter should increment each time the post is loaded on the page using views.
The code that the user is using can be seen below.
// Add our callback // Mind that we set a priority of 2 and we expect 2 arguments add_action( 'wpv-after-display-post', 'my_count_on_views', 10, 2 ); // Define our callback function my_count_on_views( $post, $view_id ) { if ( $view_id == 207615 ) { // Only do something if the current View is our View, with ID 44 $counter = get_post_meta( $post->ID, 'my_counter', true ); $counter = $counter + 1; update_post_meta( $post->ID, 'my_counter', $counter ); } }
The user is storing the counter inside a custom field but the field itself is not being updated with the value.
Solution:
The solution is that since you are using a custom field created using Types then you will need to user the wpcf- prefix when you are referencing the field using the wordpress post meta functions.
In this users case he should've retrieve the field like this wpcf-my_counter.
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.
Heute stehen keine Supporter zur Arbeit im Werkzeugsatz-Forum zur Verfügung. Sie können gern Tickets erstellen, die wir bearbeiten werden, sobald wir online sind. Vielen Dank für Ihr Verständnis.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | 9:00 – 12:00 | - |
- | 13:00 – 18:00 | 13:00 – 18:00 | 13:00 – 18:00 | 14:00 – 18:00 | 13:00 – 18:00 | - |
Supporter timezone: America/Jamaica (GMT-05:00)
Dieses Thema enthält 2 Antworten, hat 2 Stimmen.
Zuletzt aktualisiert von vor 6 Jahren, 9 Monaten.
Assistiert von: Shane.