$wpdb->get_var returns 0

Your count for that query may be 0. Make sure $wpdb->tablex is correct. Also, definitely use $wpdb->prepare $user_followed = $wpdb->get_var( $wpdb->prepare( “SELECT COUNT( * ) AS total FROM {$wpdb->tablex} WHERE type = %d AND active = %d AND user_id = %d”, 4, 1, $user_id ) );

problem with quotes on new post

$post_content=”"Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit…"”; Try encoding special characters. See: http://www.w3schools.com/tags/ref_entities.asp & http://php.net/manual/en/function.htmlentities.php

Using queries in and i see 7000+queries?

195 queries for one page is a lot. 7000 queries is not a lot, it is insane. Install Query Monitor. It tracks all queries and presents them in groups. I don’t know if it can track that many queries, this is probably an interesting stress test. 🙂 Find the source of those queries, deactivate it. … Read more

Efficiently loop over huge number of posts

Call a external script: Your function look like this: <?php function modify_posts() { $number_posts = 10; $offset = 0; $success=”success”; while ( ‘success’ === $success ) { $url = add_query_arg( array( ‘num’ => $number_posts, ‘off’ => $offset, ‘abs’ => urlencode( ABSPATH ) ), plugins_url( ‘remote_get.php’, __FILE__ ) ); $response = wp_remote_get( $url ); if ( … Read more

Complicated MySQL Query

Why not just use WP_Query for this instead of inventing the wheel all over again? I’m pretty sure you can solve this with a meta query within your WP_Query. See the codex.

MySQL: get post_tag items that are tags (not SEO keywords)

Fetching all tags of post: SELECT p.id, p.post_name, c.name, GROUP_CONCAT(t.`name`) as tag FROM wp_posts p JOIN wp_term_relationships cr on (p.`id`=cr.`object_id`) JOIN wp_term_taxonomy ct on (ct.`term_taxonomy_id`=cr.`term_taxonomy_id` and ct.`taxonomy`=’category’) JOIN wp_terms c on (ct.`term_id`=c.`term_id`) JOIN wp_term_relationships tr on (p.`id`=tr.`object_id`) JOIN wp_term_taxonomy tt on (tt.`term_taxonomy_id`=tr.`term_taxonomy_id` and tt.`taxonomy`=’post_tag’) JOIN wp_terms t on (tt.`term_id`=t.`term_id`) GROUP BY p.id order by p.id … Read more

Delete posts with word count less than x number of words

function delete_posts() { $lastposts = get_posts(array(‘numberposts’ => -1)); if ( $lastposts ) { foreach ( $lastposts as $post ) : setup_postdata( $post ); ?> <?php $content = get_the_content(); if (str_word_count($content) < 100) { wp_trash_post($post->ID); } ?> <?php endforeach; wp_reset_postdata(); }}add_action( ‘init’, ‘delete_posts’ );

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