You have added get_current_user_id();
in single quote. please remove quote from 'get_current_user_id()';
.
function get_meta_value_by_meta_key(){
$author_id = get_current_user_id();
// do stuff to get user I
$author_posts = get_posts( array('author' => $author_id, 'numberposts' => -1 ));
// needed to collect the total sum of views
$counter = 0;
// needed to collect the total sum of views
echo '<h3>Post views by Author:</h3><ul>';
// do stuff to get author name
foreach ( $author_posts as $post ) {
$views = absint( get_post_meta( $post->ID, 'Creation_Views', true ) );
$counter += $views;
echo "<li>{$post->post_title} ({$views})</li>";
}
echo "</ul><hr /><p>Total Number of views: <strong>{$counter}</strong></p>";
}
add_shortcode('Stats', 'get_meta_value_by_meta_key');
Related Posts:
- How to display multiple Post meta_key/meta_values by SQL query
- Use WP_Query in shortcode
- Random order of WP_Query results with highest meta value
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- WP_Query adds “(wp_posts.ID = ‘0’)” so no results are returned
- Archive post by meta value + 24hours
- Is it possible to retrieve all posts with a certain value for metadata?
- Order a WP_Query by meta value where the value is an array
- WordPress SQL JOIN query
- WP_Query: How to get results from both meta_key options?
- get_terms with specific id order
- get different meta-data of a complicated query at the same time
- Delete post meta by serialized meta value
- WordPress search query, how to modify the sql
- Efficient way of querying for a “fallback” post?
- SQL Query Search page
- direct query to post_meta table
- How to sort search result by post_title, then by post_content
- How Can I Call Up The Author’s Name on a Post
- phpMyAdmin displays error when importing database
- have_posts() execution failure
- Preferred Method of debugging a wordpress SQL calls?
- How to filter posts by post format “standard” from wp-json api?
- Why is variable not working on custom sql query using wpdb?
- How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?
- Can’t search posts using WP_QUERY inside AJAX Function
- How to query for pages/post depending on slug?
- How can I use wp_query to show all product data using just the products ID?
- Retrieving Author ID in wp-admin area
- Get stock by custom meta field on all Woocommerce variable products
- Custom page archive query by url var calling page twice on one of my custom queries?
- WordPress custom slug (endpoint) and compare all links
- How to query for posts with a null or blank post_name?
- WordPress pagination not working with search page
- get current custom post ID by WP_Query method
- Transferring working local PHP site to wordpress – with database (MySQL)
- how to delete 30 day old data using PHP [closed]
- Display fields as values in array from external SQL DB
- How to securely provide a $_POST var in WP_Query with PHP 7?
- Using foreach loop breaks
- The text box have space character
- how to remove metadata from the posts of my blog?
- How can I create a list of page titles from custom meta values?
- Trying to remove post thumbnail with plugin
- Randomly Assign an Image’s Alt Text Based on Data From Post
- Create WP_Query to search for posts by their categories or their parent/child categories
- WP Query with custom Shortcode
- Storing Array from returned database query and using the array in a new query
- wp_query with cat not working
- How to use an associative array in post__in with WP_Query?
- Getting the author name on author archive page
- If Query In Sidebar
- Recent Posts slider, using WP_Query(), loads duplicate sliders
- Compare post-IDs within WP_Query? (Less than / Greater than)
- Importing Geo data into wordpress database
- Detect session/cookie variable in wordpress to prevent access to documents
- How to use $query->set with post__in?
- Why do WP_Query results change after updating unrelated Advanced Custom Fields (ACF)?
- Sort custom meta column by other meta value
- Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
- Loading the same WP_Query in two different wordpress .php templates
- How to prevent WP_Query function from returning all posts when empty?
- Querying wpdb using PHP
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- Dynamic content based on a URL parameter
- Display a specific category of products in shop page and disable code for specific actions
- Creating user status mode in WordPress
- Need help with Google drive API [closed]
- Add more button if more 8 items
- How to store post ID’s in cookie or session to display the same posts later
- WordPress, AJAX and pre_get_posts using conditional tags
- Get users that likes the post
- get_posts() and WP_query limits ‘AND’ conditions to a maximum of 6 for meta value queries in WordPress
- Exclude posts based on meta value
- Recent Posts Not Showing Only On A Specific Category Page [closed]
- edit_comment_link is not showing for comment author
- Custom query, checking values of multiple meta keys
- auto-populating custom nav with all items from custom post type
- inserting a post from an extern php file but post content doesn’t show on wp site
- WordPress update_post_meta updating with empty meta_value field [closed]
- Remove echo from shortcode
- Genesis framework comments broken?
- How Can I use WP_Query to Only Display 1 Post from Custom Post Type if Query Returns Posts with Matching ID in Custom Field
- $wpdb->insert() does not Insert record in a table
- Databases – Submitting data from inputs to database [closed]
- WordPress theme options error
- Remove author link wherever author’s name is display
- Security for data obtained from the database
- Fatal error: Call to a member function query() on a non-object
- Get posts from multiple post type
- Get post id within comments loop
- How to get all author posts outside of author templates
- WP_Query fails despite having 1 post
- Create a Blog Template Page
- Non-Closing PHP Query in WordPress Loop
- unable to use ‘new WP_Query’ in AJAX call
- wp_query get the 2nd post
- Exclude posts with specific metadata from search?
- Is it best to avoid using $wpdb for security issues?
- How to get post ID in a Page?