Post X of Y in single.php / sidebar.php

class MY_Post_Numbers { private $count = 0; private $posts = array(); public function display_count() { $this->init(); // prevent unnecessary queries $id = get_the_ID(); echo sprintf( ‘<div class=”post-counter”>Post number<span class=”num”>%s</span><span class=”slash”>/</span><span class=”total”>%s</span></div>’, $this->posts[$id], $this->count ); } private function init() { if ( $this->count ) return; global $wpdb; $posts = $wpdb->get_col( “SELECT ID FROM $wpdb->posts WHERE post_status=”publish” … Read more

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