Retrieving custom fields with $wpdb->get_results

Note, before going further: Take care about portability and security: function wpse50056_get_post_meta() { global $wpdb; $results = $wpdb->get_results( ” SELECT ID, post_date, post_title, post_content, meta_key, meta_value FROM {$wpdb->posts} INNER JOIN {$wpdb->postmeta} ON ( $wpdb->posts.ID = {$wpdb->postmeta}.post_id ) ” ); foreach( $results as $result ) { printf( ‘<pre>%s</pre>’, htmlspecialchars( var_export( $result, true ) ) ); } … Read more

Inserting Post Meta From SQL

Actually, the customary way to do this in WordPress would be to use <?php update_post_meta($post_id, $meta_key, $meta_value, $prev_value); ?> as per the codex: https://codex.wordpress.org/Function_Reference/update_post_meta. It yields shorter code, and the intent of the code is clearer.

How to auto login user again after change user_login

I found when attempting similar I needed to clear the user cache to get the relogin to work (after much frustrating testing!): wp_cache_delete($user_id, ‘users’); wp_cache_delete($old_user_login, ‘userlogins’); // maybe unnecessary? $creds = array(‘user_login’ => $user_login, ‘user_password’ => $user_password, ‘remember’ => true); wp_signon($creds); Note for this to work you may also need the user to change their … Read more

How to filter sql only for a specific post type

As @bonger said, let your filters accept a second argument, which will be the instance of WP_Query that’s executing the filter, and check it is indeed the main query for an event: function single_posts_fields( $sql, $wp_query ) { if ( $wp_query->is_main_query() && $wp_query->is_singular( ‘event’ ) ) { // Do your stuff } } add_filter( ‘posts_fields’, … Read more

how to get permalink using sql

I am not sure why you are using a custom query and not get_posts() or WP_Query as you should. Anyway, you need to get the post ID … $query =”SELECT wp_posts.post_title AS title , wp_posts.post_content AS content, wp_posts.post_date AS blogdate , wp_posts.ID AS ID And then just pass this ID to get_permalink(): get_permalink( $post->ID ); … Read more

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