Knowing the total number of posts before to get into the loop

functions.php: function wpse8170_get_posts_count() { global $wp_query; return $wp_query->post_count; } index.php: if (have_posts()) : echo ‘<h1>’ . wpse8170_get_posts_count() . ‘ Posts Found</h1>’; while ( have_posts() ) : the_post(); //… endwhile; endif;

WP_Query: query posts by ids from array?

You have to use post__in (double underscore) argument, instead of post_in: echo print_r($rel); // Array ( [0] => 63 [1] => 87 ) $args = array( ‘post_type’ => array( ‘post’ ), ‘orderby’ => ‘ASC’, ‘post__in’ => $rel ); $loop = new WP_Query( $args ); If you are unsure why an argument is not working, copy … Read more

Query *only* sticky posts

I currently have no posts set as stickies on the website. Which tells me that nothing should show up in the loop. Exactly where you are wrong when passing an empty array to post__in. WordPress has some silly bugs which has no proper workaround and will most probably stay active bugs for a very long … Read more

Why do themes rely on “The Loop”?

You are thinking of WordPress templates as PHP application code. Essentially they are not that. WordPress templates by design are templates using Template Tags API. It is extra level of abstraction, that just happens to allow to use rest of PHP language too. The ease of template tags serves the popularity of WordPress and extremely … Read more

Make loop display posts by alphabetical order

To display posts in descending alphabetical order add this to your args array (taken from the wp codex) ‘orderby’ => ‘title’, ‘order’ => ‘DESC’, To display posts in ascending alphabetical order just switch DESC to ASC. So the whole thing would look like: $args = array( ‘orderby’ => ‘title’, ‘order’ => ‘DESC’, ); $query = … Read more

Exclude the category from the WordPress loop

you could use wp_parse_args() to merge your arguments into the default query // Define the default query args global $wp_query; $defaults = $wp_query->query_vars; // Your custom args $args = array(‘cat’=>-4); // merge the default with your custom args $args = wp_parse_args( $args, $defaults ); // query posts based on merged arguments query_posts($args); although, i think … Read more

Pagination returns 404 after page 20

What you are experiencing is quite normal and expected. This is one of the big reasons I always hammer on this point, never use custom queries to replace the main query on the home page or any type of archive page. They solve one issue but creates plenty other new ones Lets look at what … Read more

get_template_part from plugin

/** *Extend WP Core get_template_part() function to load files from the within Plugin directory defined by PLUGIN_DIR_PATH constant * * Load the page to be displayed * from within plugin files directory only * * @uses mec_locate_admin_menu_template() function * * @param $slug * @param null $name */ function mec_get_admin_menu_page($slug, $name = null) { do_action(“mec_get_admin_menu_page_{$slug}”, $slug, … Read more

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