Does not work for media files
-
Can’t get it to work with media files, I’ve changed the params to
$params = '&post_type="attachment"&range="monthly"&stats_views=0';yet still got ‘Sorry. No data so far.` on the page.
-
Hi there!
Indeed, WPP only tracks the following post types: post, page, and CTPs. Other post types, such as attachment, are ignored by the plugin.
If you want WPP to track attachments as well, you’ll have to make a change in the code:
- Go to Plugins > Editor and select WordPress Popular Posts from the dropdown.
- Find this line (as of version 3.2.2), and change it to:
if ( is_singular() && !is_front_page() && !is_preview() && !is_trackback() && !is_feed() && !is_robots() ) { - Hit the Update file button to save changes.
Note that any changes made to plugin files will be lost the next time you upgrade it, so you should bookmark and / or save this topic somewhere for future reference.
Thanks for your reply!
I tried this but still ‘No data so far.’ 🙁
The views count does get saved since
wpp_get_views()has valid return in myattachment.phptemplate, and this is true even before I made the code change you suggested.BTW, I noticed that
is_single,is_attachmentandis_singularall return true onattachment.php, and I made some search and the codex page also indicates this: https://codex.wordpress.org/Function_Reference/is_single#Notes.That makes sense. The attachment.php file is the single.php for media files. Never thought of that.
Gimme a second, just got home and the laptop isn’t on yet. I’m sure I’m forgetting something.
Edit: I was right, there’s an additional change to be made.
Attachments are stored in the wp_posts table with status ‘inherit’. WPP retrieves only posts with status ‘publish’. The link above should take care of that.
Thanks, this works.
Any chance this would be merged into the main branch?I may consider it. I need to know first if this change has any other side effect I may not know about (eg. under what other conditions is the ‘inherit’ status used).
The topic ‘Does not work for media files’ is closed to new replies.