How to change the case of all post titles to “Title Case”

Updating the posts $all_posts = get_posts( ‘posts_per_page’ => -1, ‘post_type’ => ‘post’ ); foreach ( $all_posts as $single ) { wp_update_post( array( ‘ID’ => $single->ID, ‘post_title’ => to_title_case( $single->post_title ) // see function below )); } Converting a string to “Title Case” And, while not pertinent to WP, for the sake of completeness: function to_title_case( … Read more

How to end the excerpt with a sentence rather than a word?

This requires PHP 5.3+ (WP requires PHP 5.2.4+) add_filter(‘get_the_excerpt’, ‘end_with_sentence’); function end_with_sentence($excerpt) { $allowed_end = array(‘.’, ‘!’, ‘?’, ‘…’); $exc = explode( ‘ ‘, $excerpt ); $found = false; $last=””; while ( ! $found && ! empty($exc) ) { $last = array_pop($exc); $end = strrev( $last ); $found = in_array( $end{0}, $allowed_end ); } return … Read more

Is there a action hook for the “Empty Trash” button?

I don’t think there exist one, but you could create your own, wpse_empty_trash, with something like this: /** * Add a custom hook ‘wpse_empty_trash’ */ add_action( ‘load-edit.php’, function() { add_action( ‘before_delete_post’, function ( $post_id ) { if ( ‘trash’ === get_post_status( $post_id ) && filter_input( INPUT_GET, ‘delete_all’ ) && 1 === did_action( ‘before_delete_post ‘ ) … Read more

Can posts have parents?

Out of the box, no, posts can’t have parents. They can be assigned to categories, which can be organised hierarchically. Pages, however, can have parents and you can build a menu structure out of them by using that feature. As to where this is enforced: The parent of a post is stored in the column … Read more

How to display related posts from same category?

One possibility: $related = get_posts( array( ‘category__in’ => wp_get_post_categories( $post->ID ), ‘numberposts’ => 5, ‘post__not_in’ => array( $post->ID ) ) ); if( $related ) { foreach( $related as $post ) { setup_postdata($post); /*whatever you want to output*/ } wp_reset_postdata(); } Reference: get_posts wp_reset_postdata wp_get_post_categories Answer re-written based on WP_Query(): $related = new WP_Query( array( ‘category__in’ … Read more

Keep featured content post in homepage with original order

I think you can use the WPQuery $the_query = new WP_Query( array( ‘post__in’ => get_option( ‘sticky_posts’ )) ); ?> <?php if ( $the_query->have_posts() ) : ?> <!– pagination here –> <!– the loop –> <?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <h2><?php the_title(); ?></h2> <?php endwhile; ?> <!– end of the loop –> <!– … Read more

Change Posts per page count

This will do it: (add to your theme’s functions.php) add_action( ‘pre_get_posts’, ‘set_posts_per_page’ ); function set_posts_per_page( $query ) { global $wp_the_query; if ( ( ! is_admin() ) && ( $query === $wp_the_query ) && ( $query->is_search() ) ) { $query->set( ‘posts_per_page’, 3 ); } elseif ( ( ! is_admin() ) && ( $query === $wp_the_query ) … Read more

How to mark every 3rd post

My approach. No extra function, no filter. 🙂 <?php $GLOBALS[‘wpdb’]->current_post = 0; ?> <div <?php post_class( 0 === ++$GLOBALS[‘wpdb’]->current_post % 3 ? ‘third’ : ” ); ?>> Alternative: <div <?php post_class( 0 === ++$GLOBALS[‘wpdb’]->wpse_post_counter % 3 ? ‘third’ : ” ); ?>>

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