Specify strict ‘order by’ in WordPress query

You could use usort(). Your callback function would need to determine the last names and sort by them. So, for instance: $args = array( ‘post_type’ = ‘Employees’, ); $employees = get_posts( $args ); usort( $employees, ‘wp91501_sort_employees’ ); and then your callback might be: function wp91501_sort_employees( $a, $b ) { // split the names into arrays … Read more

Retrieve Image Attachments Getting Post Thumbnail Image First

First, exclude the featured image (= post thumbnail) from the query, then set up the posts array as combination of the featured image and the other images. Put this directly below $args = … and above $attachments = …: if (has_post_thumbnail($post->ID)) { $featured_image = get_post_thumbnail_id($post->ID); $args[‘exclude’] = $featured_image; $attachments = array(get_post($featured_image)) + get_posts($args); } else

Number of displayed posts

The WordPress function get_posts() supports: ‘posts_per_page’ => 10, ‘numberposts’ => 10, so you should use: $projects = get_posts(array(‘post_type’ => ‘projects’, ‘numberposts’ => 10)); instead of $projects = get_posts(array(‘post_type’ => ‘projects’, ‘number posts’ => 10)); If you want to show all posts, you can use ‘posts_per_page’ => -1 You can read more about this in the … Read more

Display Posts with template on a Page

query_posts() is a horrible function and shouldn’t be used. Also it doesn’t has much to do with loading template, since it was originally designed to be used in template. Should not be used. If you are looking for logic of how WP picks template files from theme to load see Template Hierarchy. If you just … Read more

Turn get_posts as string into an array for use in theme admin options

This… array(’54’=>’Post #1′,’23’=>’Post #2′, ‘654’=>’Post #3′,) … is not a string. It is an array definition. All you need to do is create an array, which is what you want, and skip the string completely. function post_page_options(){ $post_page_options = get_posts(‘category=orderby=title&order=asc&numberposts=”); foreach( $post_page_options as $value ) : $str[$value->ID] = $value->post_title; endforeach; return $str; }

Don’t submit post if post title exists

Here’s a sample code to get you started – basically it intercepts the creation of a new post by the user-submitted posts plugin(well at least it tries to, but in general there shouldn’t be any other posts created during that request). If a post with that name already exists, we add the content as a … Read more

get_posts always returning the same number of posts = 5

get_posts() has some defaults set, including numberposts equal to 5. Since it’s not considered to be a loop by itself those are independent and not affected by admin settings. So simply pass in arguments numberposts/posts_per_page (same thing) number for how many posts you want or -1 for all matching posts.

Add Filter not working with get_posts

According with WordPress documentation, the post_where filter will not affect to the query generated by the get_posts() function. See also the default usage of get_posts() where you can see the argument suppress_filters set to true by deafult. In order to run post_where filter in the query generated by get_posts() function you have to set suppress_filters … Read more

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