how do i register global query in template

Declare an array at the start of your layout, or in your functions file depending on the scope required and populate the array with all the bands using get_posts and making the key the post ID. You will then have a global array of bands, and can pull info from each one wherever you need … Read more

Displaying Posts Attached to Custom Taxonomy Terms

The way you query for Taxonomy is deprecated, see the reference in the Codex: http://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters So instead of ‘taxonomy’=> $taxonomy, you should use this: ‘tax_query’ => array( array( ‘taxonomy’ => $taxonomy, ‘field’ => ‘slug’, ‘terms’ => $section->slug ) ) And make sure that $taxonomy is defined!

Can I use WP_Query one time and then filter the results multiple times

Wrap your WP_Query object in a function so you don’t have to change all the query $args. The function will pass parameters for custom field value and order by custom field value. Here how you can do it: <?php function custom_query($divided_cf_val=array(), $order_by_cf_val) { ?> <div id=”listings”> <?php $args = array( ‘post_type’ => ‘listing’, ‘post_status’ => … Read more

How to rearrange a pool of posts joined using two queries?

This is how I would approach it: Code function my_pseudo_date_query( $where, $query ) { global $wpdb; $dq = $query->get(‘my_date_query’); if( $dq && !empty( $dq[‘after’] ) ){ $where .= $wpdb->prepare( ” AND {$wpdb->posts}.post_date >= %s” $dq[‘after’] ); } if( $dq && !empty( $dq[‘before’] ) ){ $where .= $wpdb->prepare( ” AND {$wpdb->posts}.post_date <= %s”, $dq[‘before’] ); } … Read more

Insert images into wordpress post with a query

Yes, it is possible, WordPress does not have an API, but some useful functions. I would load all your rows into array like $your_table = [‘post_id’ => ‘image’, ‘post_id’ => ‘image’, …] Then execute a foreach loop foreach($your_table as $post_id => $image) { //full path to the image $image_path = _YOUR_FULL_ABSOLUTE_PATH.$image; /** * Get an … Read more

Query pages based on tags

This is because you haven’t mentioned post_type here and by default post_type is ‘post’ and hence it is missing the pages, add the below in your query ‘post_type’ => array( ‘post’, ‘page’ ) Like this $articles = new WP_Query( array( ‘showposts’ => -1, ‘tag’ => $tag, ‘meta_key’ => ‘date’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’, … Read more

Select column name dynamically mySQL Query

I guess one could argue that this is somewhat wordpress related, because you are trying to get_results() from $wpdb, but like @MarkKaplun said your problem is that you are using the SQL wrong. Below code is an example on how to do it correct: $dr = $wpdb->get_results( $wpdb->prepare( “SELECT * FROM wp_shipping WHERE country = … Read more