WordPress
October 5, 2021

Delete Old Post in WordPress

We want to delete old post in easy way, Add the following code to your current themes functions.php file and reload your page and see your post may have been deleted.

‘ids’,
‘post_type’ => ‘post’, //specify your post type here.
‘posts_per_page’ => ‘-1’,
‘date_query’ => array(
‘column’ => ‘post_date’,
‘before’ => date( “Y-m-d H:i:s”, strtotime( ‘-1 year’ ) ), //specify your time here.
)
);
$query = new WP_Query( $args );

// The Loop
if ( $query->have_posts() ) {
while ( $query->have_posts() ) {
$query->the_post();
wp_delete_post(get_the_ID(),true); //use this function if you are working with default posts
}
} else {
echo ‘no posts found’;
return false;
}
die();
wp_reset_postdata();
}

?>

Related Post


How to Change WordPress Post excerpt length

For Change post excerpt length add following code in your current themes functions.php file.

Disable RSS Feed in WordPress

By default WordPress generates RSS feeds for all post types, Taxonomies, Comments and etc.. that are built in, such as: http://example.com/feed/ http://example.com/feed/rss/ http://example.com/feed/rss2/ http://example.com/feed/rdf/ http://example.com/feed/atom/ There are two ways to disable RSS feed like using plugins and with custom codes. You can use many free plugins for disable RSS feeds. But let we disable RSS […]

How To Create Meta Boxes in WordPress

A meta box is a draggable box displayed in the post editing screen in the backend of WordPress. Users can select or enter extra information in meta boxes addition to the content in the main post editing area. There are two types of data you can enter in meta boxes: metadata (i.e. custom fields), and […]

How to Block Dashboard Access for Non-Admins WordPress

Removing the Admin Bar for Non-Admins Removing the admin bar is a simple code snippet. I’ve shown before how you can hide the admin bar conditionally for users. In there I’ve not mentioned how you can hide it for everyone but admins, so thats where this code snippet comes in. You need to add the […]

Disable Payments on WooCommerce

You are using WooCommerce for your eCommerce website. A thing is you want to disable payment on your website, but disabling in WooCommerce payment setting WooCommerce > Settings > Payments will not work and display There are no payment methods available. Add this code to functions.php file of theme.

WordPress Register Form Without Plugin

Are you need simple register form without plugin for your WordPress website? Yes, Then i have created [wc_register_form] shortcode with quick simple code. So you can add register form anywhere like in Pages, Posts and Widget etc… Therefore you just need to put [wc_register_form] shortcode where you need register form. So you need to follow […]


PREVIOUS PAGE

Leave a Reply

Your email address will not be published. Required fields are marked *