• Hi,
    I picked up maintenance on an older website and they realized today that their “last week’s popular posts” page was no longer pulling posts from last week, it looks to have stopped working at the end of 2020, as the last posts it is pulling are from January.

    I searched through their theme files and found that they get a query for that page with a custom function:

    function get_last_weeks_top_stories($count = 10)
    {
        $last_weeks_top_story_ids = get_option( 'last_weeks_top_stories' );
    
        $last_weeks_top_stories = new WP_Query(
            array(
                'post_type' => 'news_entry',
                'post__in' => explode(',', $last_weeks_top_story_ids),
                'posts_per_page' => $count
            )
        );
        return $last_weeks_top_stories;
    }

    Here I can see they are retrieving the IDs stored in 'last_weeks_top_stories', and if I go to their wp-admin/options.php page I can see the ID’s being retrieved in there. It appears to be pulling the ‘correct’ posts based on the data in that options file, so this leads me to believe the issue is not with getting the correct data, but whatever is SETTING the most popular posts from last week. This is where the problem is for me.

    I would think that there would have been some place in the theme or plugins files that would have an add_option(), but I cannot find where this option of 'last_weeks_top_stories' is being set at. I have downloaded the entire plugins and theme folder and searched through the files for any mention of ‘last_weeks’ and nothing comes up.

    They have a plugin installed called WordPress Popular Posts so I was thinking maybe they would be utilizing that, but I cannot see anywhere where that field would be created within that plugin either, or if that is even what they were using to populate the option anyway.

    Does anyone have any suggestions on how I could find out where this 'last_weeks_top_stories' option is being set?

    Thank you!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Moderator t-p

    (@t-p)

    I picked up maintenance on an older website. … I searched through their theme files and found that they get a query for that page with a custom function

    Is that theme up to date on this “older webdite”?

    Are all plugins up to date?

    Is the WP core up to date? The current version is 5.6.1

    Check in the actual database. (wp_options) (could be another prefix but wp_options is default).

    Moderator bcworkz

    (@bcworkz)

    What qualifies as a top story? WP doesn’t normally track popularity or importance, but a plugin could add such functionality. If such criteria existed, it seems odd that it’d be compiled into an option setting. I’d think the top stories would be directly queried by whatever criteria makes them top without going through an option.

    So it seems that the top stories might be manually selected. Someone would need to be responsible for keeping the selections updated. Has personnel changed at this organization around January? If top stories are manually selected, there’d have to be a UI somewhere for the purpose. One sneaky place to put such functionality would be a custom bulk action on the news_entry posts list table. Someone could checkmark specific stories, then apply a custom bulk action to make them top stories, which updates the option setting.

    Thread Starter sorakha

    (@sorakha)

    Hi @bcworkz,
    Thank you for the information & insight.

    I had that same question myself and was trying to figure out how they were determining what a top story was, and ended up thinking into your same line of reasoning. I actually realized the last stories were from 2019, not 2020, so it’s been quite some time and also believe that someone was manually updating these and then maybe was let go and nobody realized that the stories weren’t being updated anymore.

    I was looking to see if there was some category or tag indicating that they were top stories, or some custom field, but didn’t see anything that stood out. I’ve reached out to the previous team to if it’s possible manual selection was being done somewhere.

    I guess my main question really is indifferent to whether it is working properly or not, and mainly ‘how I could find out where an option is being set at’. Even if this was working completely fine, I would not know where this data is being set/coming from.

    I can plainly see that there are post id’s in this ‘last_weeks_top_stories’ option field, but am at a loss finding where it’s coming from. If I manually edit the post ID’s in the options it is overwritten with those same old ID’s from 2019 after I hit save on the wp-admin/options.php page. I’m not sure where to look next.

    Moderator bcworkz

    (@bcworkz)

    it is overwritten with those same old ID’s from 2019

    That behavior could be useful in narrowing down where the data is coming from. But only if it’s truly overwritten and you were not simply blocked from updating. Try making some minor but obvious change in that option directly in the DB using the phpMyAdmin app. If it’s saved as a serialized array (starts with structural data similar to a:2:{i:2;a:4:{s:5:"title";...), you can change the strings within quotes, but avoid changing the character count or the structure will become corrupted.

    If your change here still gets overwritten, there’s other code at play. If the change persists, you were just blocked from making changes in WP. If it’s really overwritten, narrow down the source by deactivating all plugins and switching to a default twenty* theme. You ought to be able to set option values within WP now. Restore your theme and plugins, one at a time, checking for changes in the option value after each. You may need to view the query results or something to trigger the auto-updating of the option value. The last activated module when there’s a change in option value is the one responsible.

    Still doesn’t answer the question of what’s happening, but at least where you need to look further is greatly reduced. You might be able to get clarification from the theme or plugin’s author through their dedicated support channel.

    Thread Starter sorakha

    (@sorakha)

    Thank you, I will try some of these out and update if I find anything further.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘WordPress Options’ is closed to new replies.