Three different post types on homepage

Since you’re not displaying a different amount of posts on the front page and on the paged pages for your main query, you don’t really need to mess around with the offset. All you need is to exclude the three posts you’ve already shown from your query, which you can do with the pre_get_posts action: … Read more

Add 20yrs to post date, and then query

An example, that uses the posts_where filter. If you need to extend a query using the posts_clauses filter, then just exchange $where with $pieces and set $pieces[‘where’] .= instead of $where .=. Just drop that into your functions.php file and add some conditional tag before querying the posts. function filter_where( $where ) { // Add … Read more

wordpress loop for specific category

Pretty sure query_posts is the worst way to query… Always use get_posts from what I’m constantly told. Remove the arguments that you don’t use on the array below. $args = array( ‘posts_per_page’ => 5000, ‘offset’ => 0, ‘category’ => , ‘orderby’ => ‘post_date’, ‘order’ => ‘ASC’, ‘include’ => , ‘exclude’ => , ‘meta_key’ => , … Read more

the_title(); works in a page template, outside the loop. Why?

The global $post object exists already for singular views before wp_head is called. It is just not filled with all data. The the_title() calls get_the_title() which in turn calls get_post(). And that calls $GLOBALS[‘post’] if no post ID has been passed. See also Generating the ogp tags in theme for a use case.

When to use wp_reset_postdata();

First we should talk about why you need to use wp_reset_query() in the first place. What wp_reset_query() does is reset the global $wp_query object back to it’s original state. Since you’re creating a new WP_Query object / instance, it does not overwrite the global $wp_query object. The only real case you would need to call … Read more

Why is it necessary to call rewind_posts() when using the loop more than once? [duplicate]

Global rewind_posts File: wp-includes/query.php 784: /** 785: * Rewind the loop posts. 786: * 787: * @since 1.5.0 788: * 789: * @global WP_Query $wp_query Global WP_Query instance. 790: */ 791: function rewind_posts() { 792: global $wp_query; 793: $wp_query->rewind_posts(); 794: } and rewind_posts from WP_Query class. File: wp-includes/class-wp-query.php 3144: * Rewind the posts and reset … Read more

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