Published post auto change status to pending after 90 days

This is one of those questions that seem easy enough, but are actually quite complicated. If you don’t want to use an existing plugin, you’ll have to write your own (and hence learn more php as this is not a please-write-my-code-for-free-site). Here’s an outline.

First you will need to select all the posts of type job which are older than 90 days and which have status “published”. Like this:

$args = array(
  'post_type' => 'job',
  'date_query' => 'XXX',
  'post_status' => 'published',
  'nopaging' => true );
$wpse251989_query = wp_query ($args);

At XXX you will need to write a query selecting the date 90 days ago (you cannot just subtract 90 from today, because that will get you a negative day if it is not yet april).

Now, you must loop through all posts you retrieve and change the status.

if ( $wpse251989_query->have_posts() ) {
  while ( $wpse251989_query->have_posts() ) {
    $wpse251989_query->the_post();
    wp_update_post(array ('post_status' => 'pending'));
    }
  }

If you dump this code in you functions.php it will be executed on every page load. You could get away with that if you have a powerful server. You could also put it behind a condition like is_admin, making sure it is only executed when an administrator is logged in. The safest way to make sure this is executed only once daily is using a cron job, which brings you into advanced php territory.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)