How do I reorder (pop and push) items from WP_Query?

You could use the Metadata API to retrieve the rw_advertising_position metadata for each post, seperate the ads from the content, and then re-insert the ads at the proper locations: /** * Extracts from an array posts with positional metadata and re-inserts them at the proper * indices. See https://wordpress.stackexchange.com/questions/210493 **/ function wpse_210493_apply_advertising_position( &$posts, $return = … Read more

Re-order media links?

Edit: Added example of outputting the attachment’s id. Assigned it to the variable $attachment_id, since that’s how the core code refers to it. Note that the $post object (for the attachment) is passed into the callback of the attachment_fields_to_edit filter, so you’ll have access to all of the attachment’s properties. Yes, this can be done … Read more

Order Admin sub-menu items?

The filter ‘custom_menu_order’ will not work on the menu order because apply_filters in wp-admin/includes/menu.php supplies false as the filtered content. You can try changing false to $menu and the filter works grand. Since we obviously can’t touch the core, here’s how I got it to work: function custom_menu_order(){ global $submenu; $find_page=”edit.php”; $find_sub = ‘Post Tags’; … Read more

order by second word in title?

There is a filter, ‘posts_orderby’, which allows you to specify your own ORDER BY clauses. In your case, the code would look something like this: add_filter( ‘posts_orderby’, ‘order_by_surname’ ); function order_by_surname( $orderby, $query ) { // first you should check to make sure sure you’re only filtering the particular query // you want to hack. … Read more

get_the_terms in descending alphabetical order

You could try this: // Get posts terms $terms = wp_get_post_terms( $post->ID, ‘winetype’, array( ‘order’ => ‘DESC’) ); $sep = ‘, ‘; foreach ( $terms as $term ) { echo $term->name; echo $sep; }

wordpress query – orderby child post date

You should be able to do this with the get_children function (see the codex), $ticket_id = 34; // assume you want to retried the replies of ticket post id=34 $args = array( ‘post_type’ => ‘support_tickets’, ‘numberposts’ => -1, ‘post_parent’ => $ticket_id, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’ ); $replies = get_children( $args ); Assuming that … Read more

Sorting posts by custom date fields (non standard date format)

You can add a posts_orderby filter to flip the meta_value: function wpse174075_posts_orderby( $orderby, $query ) { if ( $query->get( ‘orderby’ ) != ‘ddmmyy_date_format’ ) return $orderby; if ( ! ( $order = $query->get( ‘order’ ) ) ) $order=”DESC”; global $wpdb; $mv = $wpdb->postmeta . ‘.meta_value’; // Note SUBSTR() position (2nd) arg is 1-indexed. return ‘CONCAT(SUBSTR(‘ … Read more

Select All in Parent Category, Group by Child Category?

Here’s a straight up simple solution. Requires you to have the most recent version of WordPress though. (or at least 4.1) Using nested taxonomy query. Taking what you have, and just adding to it a bit. $args = array( ‘post-type’ => ‘episode’, ‘post-status’ => ‘publish’, ‘posts_per_page’ => 4, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( … Read more

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