How to write inner join using posts_clauses?

First, his filter is explained in the manual and is found in the code. If you have questions about hooks and functions, the manual and code is a good place to start looking for answers. The post_clauses hook is passed the associative array to filter, so just manipulate the where and join indices as per …

Read more

Adding profile data to database

To show extra fields in profile, use this hook: function myplugin_show_profile_extra_fields( $user ) { // echo your extra fields here } add_action( ‘show_user_profile’, ‘myplugin_show_profile_extra_fields’ ); add_action( ‘edit_user_profile’, ‘myplugin_show_profile_extra_fields’ ); And to save extra fields use following hook: function myplugin_save_profile_extra_fields( $user_id ) { if ( !current_user_can( ‘edit_user’, $user_id ) ) { return false; } update_usermeta( $user_id, …

Read more

wpdb prepare without placeholder

Short answer: You should use the way described in the documentation, sanitize anything that goes in an SQL query, and always use prepared statements. Slightly longer answer: The main use of $wpdb->prepare() is to prevent against SQL injection attacks. Here, we don’t know where ‘foo’, 1337 and ‘%bar’ come from. And that’s somewhat the deciding …

Read more

Replace Unwanted Space in Post Content URL

I think you should run this query. To replace space with dash. update wp_posts set wp_posts.post_name = REPLACE( wp_posts.post_name, ‘ ‘, ‘-‘ ); Don’t forget to change table_prefix in this. And also, keep a backup on current database before trying.

How to get EVENT based on startday, using BETWEEN

found the solution <3 Used WHERE ‘$startday’ BETWEEN dstart AND dend plus : OR dstart >= ‘$startday’ SELECT * FROM wp_posts, wp_mec_dates AS mecd, wp_icl_translations WHERE wp_posts.ID = mecd.post_id and post_status=”publish” AND wp_icl_translations.language_code=”$lang” AND (‘$startday’ BETWEEN dstart AND dend OR dstart >= ‘$startday’) AND wp_posts.ID = wp_icl_translations.element_id ORDER BY dstart LIMIT 0,6

SQL – JOIN last child

This is the solution I came up with: SELECT child_ID, posts.post_author, wp1.post_author FROM wp_posts posts LEFT JOIN ( SELECT MAX(ID) as child_ID, post_parent FROM wp_posts WHERE post_type=”ticket_reply” GROUP BY post_parent ) sl ON posts.ID = sl.post_parent INNER JOIN wp_posts wp1 on sl.child_ID = wp1.ID WHERE posts.ID = 1499

Creating a “forum” – showing last post or last commented post

You can add the standard taxonomy joins to the query: global $wpdb; $cat_id = 79; // Whatever. $sql = ” select wp_posts.*, coalesce( ( select max(comment_date) from $wpdb->comments wpc where wpc.comment_post_id = wp_posts.id ), wp_posts.post_date ) as mcomment_date from $wpdb->posts wp_posts JOIN $wpdb->term_relationships AS tr ON wp_posts.ID = tr.object_id JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id …

Read more