0

Example: [shortcode id=""]. I just want to how to dynamically fetch each post ID on Posts Lists page over archive page or normal posts page inside the shortcode placed in excerpt.

Currently I'm using Post Views plugin. Using its shortcode [post-views], I'm able to correctly display post view on each single post page. However I'm facing issue when I include the same shortcode in Excerpt to show it over Posts List Page and Archive List page. There it appears Zero.

It works fine on Posts List page, only if I give a absolute Post ID as : [post-views id="1"], currently don't have a way to fetch that ID dynamically, as get_the_ID() fetches the page ID.

While on Archive page, Shortcode syntax appear as its is in Excerpt.

Hence Could you please help extend that shortcode to auto fetch Post id even on Post Lists Page or Archive page?

2
  • I'm sorry to disappoint you, but that is a specific plugin question, which you should ask the developer of the plugin for. Commented Aug 6, 2019 at 15:14
  • I asked them, but they unresponssive. However my only question is: how to fetch Post ID on posts list page in a shortcode place. Example: [post-views id="<place>"]
    – parmanand
    Commented Aug 7, 2019 at 9:14

1 Answer 1

0

Here's the code I use:

<?php if (shortcode_exists('post-views')) echo do_shortcode('[post-views id="'.$post_id.'"]'); ?>

The if condition first checks if the plugin is active. The Post ID is my variable $post_id.

If you are inside The Loop you can get the Post ID in the loop with $post_id = get_the_ID().

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.