query_posts clarification needed

Can someone please explain how “$posts” is used within the loop? It isn’t. It returns the array of queried posts , but it is insignificant and not used at all: if you remove it than the code works the same: global $query_string; query_posts($query_string.’&cat=-9′); if (have_posts()) : while (have_posts()) : the_post(); … endwhile; endif; This is … Read more

How to put forward a blog post

You can do this with Sticky Posts feature in WordPress. When you make a post sticky, it shows up above your new posts. As name suggests, that particular post will stick at top, first in the row for as long as you want. Sticky Posts is a feature introduced with Version 2.7. A check box … Read more

Order for custom field after the loop

Regions and cities fit perfectly in the concept of taxonomy: a way to group things (i.e. posts). And not so much in the concept of meta data. I strongly recommend to use custom taxonomies for that instead of custom meta fields. You will gain in performance and you will have a better data relationship management. … Read more

Multiple posts/pages in one page?

More complex way I use it this way (I’m usually doing one page design, however the method of loading pages is still same). Fo Theme options, I’m using Option tree plugin where my clients could just checkbox which pages should appear there (it’s passed by it’s ID) and than I load it into the script. … Read more

Get next/prev image/attachment in time with date query

Based on the answer by @jan-becker I build this snippet. This works for me: /* * Get the next/prev image id inside c-tax: my_snapshot_position_ctax */ function my_return_relative_attachment_id( $this_post_ID, $prev = true ) { global $post; // overwrite global $post variable $post = get_post( $this_post_ID ); // filter sql query to work with attachment add_filter( ‘get_next_post_where’, … Read more

Way to cache a query for 24 hrs

You can use WP_Object_Cache combined with a persistent cache plugin or you can use Transient API. WP_Object_Cache: // Random post link function randomPostlink(){ $cache = wp_cache_get( ‘random_tip_link’ ); if( $cache ) { echo $cache; } else { ob_start(); $RandPostQuery = new WP_Query(array(‘post_type’=>array(‘tip’),’posts_per_page’ => 1,’orderby’=>’rand’)); while ( $RandPostQuery->have_posts() ) { $RandPostQuery->the_post(); echo the_permalink(); } wp_reset_postdata(); $cache … Read more

How to use ‘WP_Query’ or ‘query_posts’ to display content in a descending order

You can store the counts as key and link a value and sort them before display like this : $sort_tab = array(); while (have_posts()) : the_post(); if ( has_post_thumbnail() ) { the_post_thumbnail( array(40,40) ); } $url = get_the_permalink(); $json = file_get_contents( ‘https://graph.facebook.com/fql?q=SELECT%20like_count,%20total_count,%20share_count,%20click_count,%20comment_count%20FROM%20link_stat%20WHERE%20url%20=%20%27’ . $url . ‘%27’ ); $json_data = json_decode($json, false); $sort_tab[$json_data->data[0]->total_count] = $url; endwhile; … Read more

Creating attachments archive in tags and categories

The WP_Query documentation on the codex specifically says: ‘attachment’ – an attachment. Whilst the default WP_Query post_status is ‘publish’, attachments have a default post_status of ‘inherit’. This means no attachments will be returned unless you also explicitly set post_status to ‘inherit’ or ‘any’. I am not sure why it was working before because this is … Read more

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