Articles of query

How to overwrite orderby with add_query_var

So I would like to have an archive that displays its posts in a random order. <?php $query = new WP_Query($query_string.”&orderby=rand”); ?> But also then if the user chooses they can order the posts differently by clicking a button. <?php $sort_date = add_query_arg(array(‘orderby’=>’date’,’order’=>’asc’)); $sort_name = add_query_arg(array(‘orderby’=>’title’,’order’=>’asc’)); ?> <div class=”sort”> Sort by: <a href=”<?php echo $sort_date; […]

Some doubts about how the loop work (trying debugging it)

I am very new in WordPress development (and also in PHP development, I came from Java and C#). Today I have installed Aptana and configured XDebug to inspect what happens into the TwentyTwelve theme. In particular, I am trying to understand how WordPress load the posts in the loop (debbuging it). So, up until now, […]

How do you display the number of a post in a query?

I want to display the number of a post beside each post title in a query, such that it literally appears like this: Post title one in query Post title two in query Post title three in query How do I do this? <?php function ngtj_get_some_posts( $category_name ) { // set the criteria $args = […]

mySQL queries are executed twice on wordpress website

I’m sorry for my english. I’m trying to add some functionalities at my WordPress website and to do this i have added a function in my function.php theme. The idea is to save in a custom table some datas and create a wp_post for any element added in the custom table. I hooked the function […]

WP_User_Query with more than two custom meta values

I am trying to create a custom user query based on users‘ metadata. I have the following query created. $users = new WP_User_Query( array( ‘search’ => ‘*’ . $search_name . ‘*’, ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘key’ => ‘Status’, ‘value’ => $search_status, ‘compare’ => ‘LIKE’ ), array( ‘key’ => ‘Operation’, ‘value’ => $search_operation, […]

How do I get all results from my query

I have written some php code and using the class.pagination.php, am able to paginate it based on a max posts per page that I set inside my code. This works great. However, it is only returning 11 posts and I know that I have 186 posts, I am so stuck, any help would be appreciated. […]

Function to limit number of custom post types on homepage – TwentyTen

here is the deal… I got hold of this piece of code to change the default post type shown on my TwentyTen child theme’s homepage. It works like a charm when I add this code to the functions.php file, but I would like to also limit the number of posts to 1 (or 2) instead […]

Wrap/close 'query' for a first-letter ordered listing of posts

Sorry for the title, I didn’t know how to call it better. I am working on a site on which I am building a listing of doctors being ordered alphabetically by last name/word of title, while all posts belonging to a letter should be grouped together below it, just like this: A Dr. John Arbuckle […]

shorthand syntax for custom fields

I’m trying to write a shortcode and am sorely out of practice with this stuff. It’s for a plugin Full Width Audio Player and I’m trying to query all tracks within a certain playlist so it will output the track names to add to the player queue. function kc_tracks ($atts, $content = null) { extract(shortcode_atts(array( […]

Re-sort get_posts query results

I have a query that pulls fields from the 3 most recent posts for a carousel: get_posts(‘posts_per_page=3’) I need to re-order the results so that instead of it being 1, 2, 3 it is 3, 1, 2. Any ideas on how to do this?