How to get a meta value from all post

get_col() function returns only one column as array. To get two column result we can use get_results(), Which will return an array of objects Which further can be converted into required structure using foreach loop. Example – function get_meta_values( $key = ”, $type=”post”, $status=”publish” ) { global $wpdb; if( empty( $key ) ) return; $r … Read more

Best practice for multiple queries on page

WP_Query can handle all of these cases. See the section on handling multiple taxonomies. $this_cat=”interviews”; $this_tag = ‘angelina-jolie’; $args = array( ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => $this_cat ), array( ‘taxonomy’ => ‘post_tag’, ‘field’ => ‘slug’, ‘terms’ => $this_tag ) ) ); $interviews = new WP_Query( … Read more

How to create a dynamic page based on form data with a plugin?

Something like this should work, though I’m not sure how meta, title, etc.. will behave, you’ll want to test everything thoroughly! function my_template_redirect() { global $wp; $qvs = $wp->query_vars; if (array_key_exists( ‘laundry’, $qvs && $qvs[‘laundry’] == ‘thank-you’ ) { global $wp_query; $wp_query->set( ‘is_404’, false ); // … now what? $post = new stdClass(); $post->ID= -99; … Read more

How to pass custom parameter to WP_Query for filtering in pre_get_posts

You can access query variables (including custom ones) via the WP_Query::get() method. For example: $my_query = new WP_Query( array( … ‘wpse105219_custom_var’ => ‘foobar’, … ) ); To ‘catch’ this at pre_get_posts: add_action( ‘pre_get_posts’, ‘wpse105219_pre_get_posts’, 10 ); function wpse105219_pre_get_posts( $query ){ if( $query->get( ‘wpse105219_custom_var’ ) == ‘foobar’ ){ //Alter $query } }

Adding a term name from a custom taxonomy assigned to a post link displayed by a wp_query loop based on another taxonomy

Something like this should help: <?php $post_type=”animals”; $tax = ‘vertebrate’; $tax_terms = get_terms($tax); if ( $tax_terms ) { foreach ($tax_terms as $tax_term) { $args = array( ‘post_type’ => $post_type, “$tax” => $tax_term->slug, ‘post_status’ => ‘publish’, ‘posts_per_page’ => -1, ‘caller_get_posts’ => 1, ‘orderby’ => ‘title’, ‘order’ => ‘ASC’ ); // $my_query = null; <- REMOVE THIS, … Read more

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