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’ : ” ); ?>>

Get the Current Page Number

When WordPress is using pagination like this, there’s a query variable $paged that it keys on. So page 1 is $paged=1 and page 15 is $paged=15. You can get the value of this variable with the following code: $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; Getting the total number of pages is a bit trickier. … Read more

Should we trust the post globals?

There is a sad truth: you can never ever be sure that some code will not break your code, and there is nothing you can do to prevent that. Especially in WordPress, where everything is global. That said, yes, global $post is one of the most used global var, so using special care for it … Read more

Print Current Post Index number within Loop

Actually I want to assign ID’s as per post index ! Here’s your code that I modified. <?php global $wp_query; $posts = $woo_options[‘woo_latest_entries’]; query_posts(‘post_type=post&category_name=company’); if ( have_posts() ) : while ( have_posts() ) : the_post(); $count++; $index = $wp_query->current_post + 1; ?> <div id=”my_post_<?php echo $index; ?>”> <!– Post Content Goes Here –> </div> <?php … Read more

How to add an admin notice upon post save/update

The reason this doesn’t work is because there is a redirection happening after the save_post action. One way you can acheive want you want is by implementing a quick work around using query vars. Here is a sample class to demonstrate: class My_Awesome_Plugin { public function __construct(){ add_action( ‘save_post’, array( $this, ‘save_post’ ) ); add_action( … Read more

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