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

Custom $wpdb returns unexpected time based results

This may be your problem: $wpdb->terms.slug = ‘another-sample’ OR $wpdb->terms.slug = ‘sample’ AND //the date logic doesn’t seem to qork quite right $wpdb->posts.post_date > DATE_SUB( NOW(), INTERVAL 7 DAY)”; Your OR operator might be confusing the query. Try using parentheses: ($wpdb->terms.slug = ‘another-sample’ OR $wpdb->terms.slug = ‘sample’) AND //the date logic doesn’t seem to qork … Read more

Custom SQL query ORDER BY term_order

In your case you are referring ORDER BY {$wpdb->terms}.term_order and as default in wordpress wp_terms table don’t have this column the term_order column resides in the wp_term_relationships table and you are referring wp_terms table to ORDER BY this column which is not is present in that table instead of this you have to do something … Read more

$wpdb->get_col and ORDER BY?

You don’t want ORDER BY $wpdb->postmeta.post_id rand(). If you had debugging enabled, you’d see an error. You need to separate ORDER BY values with a comma– ORDER BY $wpdb->postmeta.post_id, rand(). In your case, that won’t do any good because the first value gets precedence, so the query will order by the ID and then randomize … Read more

Mixing variables into an array when inserting values

You are creating a string …. $sql=””ft_num”=>””.$ticket[‘number’].'”,”booking_id”=>”‘.$ticket[‘booking’].'”‘; … but expecting it to operate as an array… array( $sql, ‘event_id’ => $event[‘id’], This has nothing to do with how WordPress does anything. This is pure PHP. You have literally created this: array( [] => “ft_num”=>”‘.$ticket[‘number’].'”,”booking_id”=>”‘.$ticket[‘booking’].'”, ‘event_id’ => $event[‘id’], You need to build the array dynamically. $dynargs … Read more

How to stop $wpdb from prepending database name

The behavior I described in my post only happens when you are using $wpdb->update to execute an UPDATE statement. If you want to update a different database using the same connection, use $wpdb->query to send a raw query, WP won’t modify it then.

How to fetch records from database WordPress

wpdb is a simple wrapper around the mysql_* functions, but you can’t mix and match them. $wpdb->query does not return the database reference that mysql_fetch_row needs. It … … returns an integer corresponding to the number of rows affected/selected. If there is a MySQL error, the function will return FALSE. (Note: since both 0 and … Read more

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