Checking for existing title in custom db query not working

use get_page_by_title to get post by title. I check for it on my system $post_exist=get_page_by_title( ‘Hello world!’, ARRAY_A, ‘post’ ); if( ! empty( $post_exist ) ) { echo ‘title exist’; } else { echo ‘title not exist’; } Running successfully. In your case it may be like $title=trim($titles_arr[$i]); $post_exist=get_page_by_title( $title, ARRAY_A, ‘post’ ); if( ! … Read more

custom user meta query

Actually i figured it out now using join SELECT a.ID FROM wp_users a INNER JOIN wp_usermeta b ON b.user_id = a.ID AND ( ( b.meta_key = ‘firstname-groom’ AND b.meta_value LIKE ‘Darren’ ) OR ( b.meta_key = ‘firstname-bride’ AND b.meta_value LIKE ‘Someone’ ) OR ( b.meta_key = ‘lastname-bride’ AND b.meta_value LIKE ‘Cool’ ) ) INNER JOIN … Read more

Query from multiple category (and)

Have you looked up the WP Codex on WP_Query for categories? They provide an example here. Also your category variable should probably only have one $. The way you’ve written your custom query also looks wrong, are you using WP_Query? $query = new WP_Query( array( ‘category__and’ => array( 2, 6 ) ) );

WordPress Mysql query and Duplicate

There’s no need for custom SQL here, use the power of meta queries: $posts = get_posts( array( ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘key’ => ‘Country’, ‘value’ => ‘UK’, ), ), ) ); foreach ( $posts as $post ) $cities[] = get_post_meta( $post->ID, ‘city’, true ); foreach ( array_unique( $cities ) as $city ) … Read more

Get categories of queried posts

You need a: array of post id ( ok ) array of category id ( not yet ) array of category id/name with unique value ( not yet ) using wp_get_posts_categories( $post_id ); returns an array of category id, so you can loop your $ids calling this function to collect all categories id. with the … Read more

Query Custom Post by taxonomy multiple categories

This should give you an OR relationship: $args[‘tax_query’] = array( array( ‘taxonomy’ => ‘category’, ‘field’ => ‘id’, ‘terms’ => array(1,2), ‘operator’ => ‘IN’ ) ); As would this: $args[‘tax_query’] = array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘project-type’, ‘field’ => ‘id’, ‘terms’ => array(1) ), array( ‘taxonomy’ => ‘project-type’, ‘field’ => ‘id’, ‘terms’ => array(2) … Read more

The best way to collision check in WP

I don’t think there is a built in mechanism for searching the meta table for a key/value pair other than a full blown post search with WP_Query. I’d consider that overkill. Just query the table: $unique = $wpdb->get_var( “SELECT meta_id FROM {$wpdb->postmeta} WHERE meta_key = ‘unique_code’ AND meta_value=”{$random}” LIMIT 1″ ); I can’t help but … Read more

Dynamically generated URL and Content page

Firstly, don’t forget to always flush your rewrite rules by going to Settings -> Permalinks and just clicking on Save Changes Now on your problem, it seems that you’re missing an ‘&‘ in your query: $new_rules[‘^test-directory/(.*)/(.*)’] = ‘index.php?test-directory=$matches[1]&test-code=$matches[2]’; Notice the & after $matches[1] On the other hand, your ‘template_redirect’ action is not calling the correct … Read more