Add 20yrs to post date, and then query

An example, that uses the posts_where filter. If you need to extend a query using the posts_clauses filter, then just exchange $where with $pieces and set $pieces[‘where’] .= instead of $where .=. Just drop that into your functions.php file and add some conditional tag before querying the posts. function filter_where( $where ) { // Add … Read more

SQL query to update post_date (one post = one single date & time)

I would not do this with SQL. A relatively simple PHP loop should work. function bulk_schedule_posts_wpse_105834() { $args = ( array( ‘cat’ => 1, ‘posts_per_page’ => -1, ‘post_status’ => ‘draft’, ‘post_type’ => ‘post’, ) ); $posts = new WP_Query($args); if (!$posts->have_posts()) return false; $date=”2013-08-01″; $times = array( ’10:00′, ’14:00′, ’17:00′, ’20:30′ ); while ($posts->have_posts()) { … Read more

How to remove published date from RSS feed

Note that if you remove the <pubDate> tag from the rss2 feed, then it will become unvalid. So you don’t want to do that! If it’s empty: <pubDate></pubDate> then the feed will still not validate: > pubDate must be an RFC-822 date-time So that wouldn’t be an option either. If you want it static, for … Read more

How to display Last Updated date from the latest post for a category list

<?php // select all sub categories of parent cat with id ‘8’ $categories = get_terms( ‘category’, array( ‘orderby’ => ‘ID’, ‘parent’ => 8 ) ); // For each sub category find last post foreach ( $categories as $category ) { $args = array( ‘cat’ => $category->term_id, ‘post_type’ => ‘post’, ‘posts_per_page’ => ‘1’, ‘orderby’ => ‘date’, … Read more

How to stop a user from updating the post date

As @t-f pointed out in his comment to question, you have an error on checking current user capability: ‘delete_published_posts’. $post_author_id simply doesn’t exist. After that, for your scope probably is a better hookin the filter wp_insert_post_data instead of the action save_post: because this one run when the post was already saved / updated, so if … Read more

Keeping post_date same as the pending post_date on privately publishing the post

@Howdy_McGee is on the right track in his comment: by the time transition_post_status is fired, the post has already been updated (i.e., written to the db). What you need to do is hook into wp_insert_post_data, instead of transition_post_status, as follows: add_filter (‘wp_insert_post_data’, ‘mycpt_keep_pending_date_on_publishing’, 10, 2) ; function mycpt_keep_pending_date_on_publishing ($data, $postarr) { if ($data[‘post_type’] != ‘mycpt’) … Read more

Date, Time, and Timezones

What is the purpose of the timezone setting in the Admin -> Settings section? Since WordPress handles time zone on its own (separately from native PHP functionality) that is where the setting made and result is stored in options. Whenever anything that works with timezones needs to happen, the time zone setting is retrieved and … Read more

Post date vs. event date in WordPress

I’m not sure about a plugin, but you can definitely add custom meta that allows you to set the event date, or even an event daterange (my preferred way of handling this is an event date and a duration, cuts down on calculations in the backend and is generally easier to understand, but ymmv). This … Read more

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