get images attached to post

It’s better to use get_children than get_posts. Here is a quick example that will work. This is in the form of a function that is defined in your plugin or in functions.php then use the function as a template tag. /** * Gets all images attached to a post * @return string */ function wpse_get_images() … Read more

WP_Query orderby taxonomy term value (numeric)

No, there is no way to do this with default WP Core. @heathenJesus talks about meta data not taxonomies. See http://scribu.net/wordpress/sortable-taxonomy-columns.html for a proper solution. And a more thorough explanation of why this is not something built into Core: Using wp_query is it possible to orderby taxonomy?

Reverse chronology of post listing

You can add code below to the beginning of loop.php add_action(‘pre_get_posts’, ‘wpse_change_post_order’); function wpse_change_post_order($query){ $query->set(‘order’,’ASC’); $query->set(‘orderby’,’date’); } the oldest posts will be in the home page.

WP_Query using meta_query with relation OR and orderby meta_value doesn’t work

The issue is that WordPress are getting all posts that has a ‘startDate’ meta key, no matter the meta value. You can understand that form this part of the request: … AND ( wp_postmeta.meta_key = ‘startDate’ OR ( mt1.meta_key = ‘startDate’ AND CAST(mt1.meta_value AS CHAR) >= ‘20140305’ ) OR ( mt2.meta_key = ‘endDate’ AND CAST(mt2.meta_value … Read more

How to add custom query filters in WP_User_Query

The pre_user_query action hook in WordPress will allow you alter the SQL statements in the WP_User_Query object before they are run against the database. Note, this is an action, not a filter, so there’s no need to return the $user_query that gets passed in. add_action( ‘pre_user_query’, ‘add_my_custom_queries’ ); function add_my_custom_queries( $user_query ) { $user_query->query_fields .= … Read more

Pagination with 5 posts per page

This is working for me on a single page using a template. Just be sure to set next_posts_link( ‘Older Entries »’, $the_query->max_num_pages );. // set the “paged” parameter (use ‘page’ if the query is on a static front page) $paged = ( get_query_var( ‘paged’ ) ) ? get_query_var( ‘paged’ ) : ‘1’; $args = array … Read more

ACF datepicker meta_query Compare Dates in m/d/Y g:i a – Not in Ymd Format

There should not be any need to do this. Even if an ACF Field is using ‘return_format’ => ‘m/d/Y g:i a’, The post_meta value is in YYYY-MM-DD 00:00:00 format. $date_now = date(‘Y-m-d’); $args = [ ‘meta_key’=>’the_date’, ‘meta_value’=>$date_now.’ 00:00:00′, ‘meta_compare’=>’>=’, ]; $query = new WP_Query( $args ); Edit: I’ve noticed some discrepancies in this, the value … Read more

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