Tag Info

Hot answers tagged

2

I think the general suggestion is to use WP_Query instead of query_posts partly because query_posts used WP_query in a simplified way and can cause problems down the road. So for sure check out the WP_Query page, specifically the Multiple Loops example: http://codex.wordpress.org/Class_Reference/WP_Query#Multiple_Loops So the code using WP_Query would look ...


2

The question was for Wordpress 3.0, but just in case someone has the same question for a more recent version, from Wordpress Codex: "Starting with version 4.1, meta_query clauses can be nested in order to construct complex queries." http://codex.wordpress.org/Class_Reference/WP_Query#Custom_Field_Parameters So that query should work on the current ...


1

Don't run a custom query to get the post count. This is already done by the main query. What you are doing is the same as eating the same piece of meat twice. :-) As said, the main query already return the amount of posts found via the $found_posts property. You can access and display it anywhere on a page as follows echo $wp_query->found_posts; This ...


1

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 ...


1

If you're altering the main query, always use pre_get_posts to alter query parameters before the query is run and before the template is loaded. This will be the most efficient and will not break pagination. As of v4, orderby accepts an array of arguments, which gives you the ability to have different order for each if necessary: function my_get_posts( ...


1

First of all, never ever make use of query_posts. It is not just slow and reruns queries, but it breaks pagination, page functionalities and the globals like $post on which some theme functionalities and plugins rely. If you really need to run custom queries (which is totally unnecessary in this case), make use of WP_Query or get_posts. All your template ...


1

Try this in the foreach loop: $thumb_url = wp_get_attachment_image_src( $attachment->ID, 'full' ); And this for the img src: echo $thumb_url[0];


1

If you are trying to omit posts 1,3,5 from category 3 on your blog, you can use the following code $query = new WP_Query( array('cat' => 3, 'post_type' => 'post', 'post__not_in' => array(1,3,5) ) ); The query results will not show posts with ids 1,3,5 of category 3.



Only top voted, non community-wiki answers of a minimum length are eligible