How to retrieve elements from another table in a SQL query?

With a WP_Query() you can have all of them what you want in an easy way. See all the arguments available in the Codex. With the following code, we are grabbing all(-1) the posts from wp_posts table, and using the post ID we are grabbing the postmeta items. <?php $productquery = new WP_Query( array( ‘post_type’=>’wpcproduct’,’post_status’=>’publish’,’posts_per_page’=>-1 … Read more

Custom Post type is being ignored in query

I found out that I was using pre_get_post on these pages to exclude some things on the taxonomy archive pages. add_action( ‘pre_get_posts’, ‘exclude_cpt’ ); function exclude_cpt( $query ) { if ( $query->is_tax(‘results_categories’) ) { $query->set( ‘post_type’, array(‘results’) ); } return $query; } BUT I forgot to make sure this was only happening in the main … Read more

You have an error in your SQL syntax – Help with query

If that is the error, a couple of things could be going on. The part that uses ‘require’, ‘require_once’ and ‘include’ is not likely correct in the code. Each of these code statements should end with a semi-colon [;] not a comma [,] hh3_ I expect is the table prefix initially used in your database. … Read more

Get all user meta by meta key instead of ID

Two options. The first will keep you away from custom SQL, and should be a lot more efficient than what you currently have. It runs two queries, one to get the user ID with the highest hourly rate, and then again to get the lowest. You need one more query to update the user meta … Read more

Include posts from feature category in pre_get_posts

I haven’t run this code so there may be a syntax error, but the gist is to return userfeed-taxonomy with the terms specified that have featured category OR cities-taxonomy with the terms specified and featured category OR anything else that’s not those taxonomies. It’s kind of clunky, maybe there is a better way: $query->set( ‘tax_query’, … Read more

Select query for a login

You can use wp_signon function Here is an example $creds = array(); $creds[‘user_login’] = ‘example’; $creds[‘user_password’] = ‘plaintextpw’; $creds[‘remember’] = true; $user = wp_signon( $creds, false ); if ( is_wp_error($user) ) echo $user->get_error_message();

Error when using setup_postdata()

You are getting the error because, by default, wp_get_recent_posts returns an array of posts (due to backward compatibilty) and not the required WP_Post object which is required to setup the template tags. Look at the source code, and you will see that wp_get_recent_posts is a simple wrapper function for get_posts (which is just a wrapper … Read more

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