Duplicate posts

You can use a static class property to store a rolling list of posts that are used in previous queries. This method allows you to pass data between classes (widgets, modules, plugins, etc…), but will also work for a procedural workflow. Everything on the page that uses your intermediary class will know what posts to … Read more

Custom permalinks – post type – hierarchical taxonomy’s

Thanks for referencing my solution. You forgot one part though – defining the rewrite of your cpt. From my solution: First get your slugs right when defining your custom post types and taxonomies: for the custom post type it should be basename/%taxonomy_name% and the slug for your taxonomy should be just basename. Dont forget to … Read more

How to avoid duplicate posts on front page?

Don’t use an && like that. And don’t use query_posts() in the first place (It’s meant for modifying a query, not performing a separate query!) Instead, do your first selection, then pull out the IDs of the posts in that selection and pass them into the second query. $fruit = get_posts( array( ‘posts_per_page’ => 3, … Read more

Code to auto expire posts after 30 days

There are some issues with your query $daystogo = “30”; $sql = “UPDATE {$wpdb->posts} SET post_status=”draft” WHERE (post_type=”post” AND post_status=”publish”) AND DATEDIFF(NOW(), post_date) > %d”; $wpdb->query( $wpdb->prepare( $sql, $daystogo ) ); You do not want to untrash trashed posts by declaring them as draft, right? And you really do not want to make every automated … Read more

Update post date on every new comment?

From what i understand, you want to change the post’s modification time whenever a comment is left on your post. For this, you need to hook into the wp_insert_comment hook and update the post’s date manually: add_action(‘wp_insert_comment’,’update_post_time’,99,2); function update_post_time($comment_id, $comment_object) { // Get the post’s ID $post_id = $comment_object->comment_post_ID; // Double check for post’s ID, … Read more

Automatically added brs and paragraphs?

You can postpone the wp_autop filter. WordPress has this filter enabled by default. And it is processing before the shortcode output. remove_filter( ‘the_content’, ‘wpautop’ ); add_filter( ‘the_content’, ‘wpautop’ , 12); Add this to your functions.php and check if the problem persist! See a similar problem here: stray <p> elements

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

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