Update existing post dates to random dates

Question How to change the post date to a randomly generated date? Answer This is fairly straightforward. What I did was to create a plugin that upon activation get all the posts, loops through them, generates a random date, and updates the post with that date. <?php /** * Plugin Name: WPSE 259750 Random Dates … Read more

How to get posts by content?

You have to extend the db query to search in the post_content column. There is a filter: ‘posts_where’ you can use. I would write a simple wrapper for get_posts() to extends its arguments an run the filter once. Example: class T5_Posts_By_Content { protected static $content=””; protected static $like = TRUE; /** * Mapper for get_posts() … Read more

publish_post hook isn’t working for scheduled posts

I reworked (added another version of) my function to remove the if statement to check post status, as the post is scheduled to publish it turns out i don’t need to check it again. /* the function */ function tcr_tweet2($postID) { /* get the post that’s being published */ $post = get_post($postID); $post_title = $post->post_title; … Read more

Prevent duplicate posts in wp_insert_post using custom fields

To save the link in the post meta you can use update_post_meta like this for example: $url = “http://sample.com/entertainment/default.aspx?tabid=2305&conid=102950” $my_post = array( ‘post_title’ => “$title”, ‘post_content’ => “$content”, ‘post_status’ => ‘draft’, ‘post_author’ => 1, ‘post_category’ => array(1), ); $post_id = wp_insert_post( $my_post ); update_post_meta($post_id,’source_link’,$url); and to prevent the insertion add a simple conditional check: $args … Read more

How to lock content?

You could hook into template_redirect, check if it is a singular page (post, page, custom post type) and force a log in: add_action( ‘template_redirect’, ‘login_to_see_content’ ); function login_to_see_content() { if ( is_singular() && ! is_user_logged_in() ) auth_redirect(); // does nothing for logged in users } As suggested by @s_ha_dum in the comments, an additional ! … Read more

Are all ID’s used unique?

If you look at the description for the different tables used by WordPress, the columns described as “auto_increment” will be unique. I am not sure what you are doing though. The URL structure you are using is not one that I recognize. That is, the syntax I think you want is this: example.com/?p=1774 rather than … Read more