This code requires WordPress 3.1 and above!
Add this function and hook to your functions.php to enable searching the first_name and last_name fields on the Admin Users page. Also enables sorting by lastname, firstname using the special ‘byname:’ prefix to the sort text.
By default, the ‘Search Users’ box on the Admin Users page only checks fields present in wp_users. This function uses the pre_user_query hook to add wp_usermeta rows having the meta_key of either ‘first_name’ or ‘last_name’ to the FROM clause. Then, it modifies the WHERE clause to add the check for the search term.
Here is the code: Continue reading
The code below can be added to your functions.php to provide a shortcode which will list post titles.
When you add the code to functions.php, you must be careful, because any errors will make your site unusable. BACK UP your functions.php before adding this, and make sure that you know how to restore from the backup.
If your functions.php file ends with ‘?>’, just paste the entire code on the line following it. If it does not end in ‘?>’, remove the ‘<?php’ line and the ‘?>’ line from the code below before pasting it in.
Once the code has been added to functions.php with no errors, create a new Page to display your titles. Enter any content you want on the page. Where you want the list of titles to show, enter the shortcode as shown in the comments in the code. Continue reading
A number of requests have been posted for a way to use sticky posts when displaying a category. The code below can be used to modify your category.php to use for all categories, or as category-id#.php to use for a given category id.
The code is an example only. It must be used to modify your code to fit your theme.
Several persons have asked for a template to list posts or pages by the first letter of the title. The code below is set for posts, but is easily modified for pages or custom posts. The CSS will need to be modified to fit your own theme.
This template lists a set number of post titles per page. See this Tip for a template that lists one letter per page.
Here is a screenshot of the first page:
If you want to have several posts in a row across the page, you can use code similar to this. This code is an example. You will need to customize it to your theme.
The important things to note are:
- the use of $post_counter to create the divs for each row
- the creation of a div with class=”post_class” to contain each post
- the use of CSS to set the width of post_row and post_class
You will need to add the CSS to float the posts left, set the width, and probably set some margins. There is some sample CSS following the code. Continue reading
If you want to override the original arguments, you must merge your argument array last (reverse of what is shown in Codex):
global $wp_query; query_posts( array_merge( $wp_query->query, array('cat' => 1) ) );