• How do I find the postmeta key with which the value of a particular flag is saved and change the value in SQL for a bulk of them?

    Or maybe is not postmetameta?

    I need to unflag “Featured post option” from all the articles in range of time from 2008 to 2011

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    “Featured post option” isn’t something offered by core WP. There is a “sticky post” feature, where the applicable IDs are saved as an option value, but that may not be how “featured posts” are managed. Featured post is likely something your theme has implemented. You could ask in your theme’s dedicated support channel how they are saved. You could trace through theme source code to find where/how featured posts are saved.

    You could poke around in the phpMyAdmin app (low level access to the database) looking for clues. For example, if you designated a featured post which has never been featured before, if such a value is saved in postmeta, the applicable record will likely be near the bottom of the table and one of the few using that particular post’s ID. Or use the search feature to find all records using that posts’s ID. Hopefully the key value is recognizable as one for featured posts.

    If not found in postmeta, there’s a chance it’s in the theme_mod option for your theme.

    Thread Starter manuelperrotta

    (@manuelperrotta)

    How can I backup and than save and delete all posts from 2012 to 2015?

    Moderator bcworkz

    (@bcworkz)

    You can use the built-in export tool to save posts in a date range. It’s wise to verify that an import plugin can successfully import the exported data before deleting the posts.

    Don’t try to use SQL or phpMyAdmin to delete directly, unless you’re very good at SQL and understanding the taxonomy tables. You’re very likely to leave many loose ends otherwise. The safe approach is with custom PHP code. Query for all posts you want removed using WP_Query class’ “date_query” argument. Then loop through the results one by one, deleting each in turn.

    If there are many many posts to delete, this is going to take some time, risking hitting PHP’s max execution time limit. You could increase this with something like @ini_set('max_execution_time', 120 ); added to wp-config.php. Don’t make it too long though, or you could introduce usability issues.

    If there’s still too many posts for the time allotted, limit the posts returned with the “posts_per_page” argument of WP_Query. Then rerun the removal code multiple times until it can no longer find posts within the specified range.

    You could instead use the back end posts list table to bulk delete the posts listed on one screen. The posts per screen can be increased up to 99 I believe. So you’d only be able to delete 99 posts at a time this way. This may or may not be quite tedious to do, but might still be faster than developing custom deletion code.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘postmeta key trigger sql’ is closed to new replies.