Style Post Differently In Query

You can set an array for the class of the div, and then inser the value of that variable as a class in the div. And create those classes in your stylesheet. In your code, the_thumbnail is inside the if($i==0), so it only prints when $i==0. Then the what’s outside the if prints just titles, … Read more

Query Strings and Woocommerce

I think that I figured this out. In my functions.php file I had the below function to redirect to the checkout page when a product is added to the cart. So I captured the username variable there and then added it to the redirected URL: add_filter (‘add_to_cart_redirect’, ‘redirect_to_checkout’); function redirect_to_checkout() { global $woocommerce; $checkout_url = … Read more

Search query -> Show all pages except certain template

REWORKED ANSWER TO ANSWER THE QUESTION In order to exclude all pages with a certain template, all you need to do is to run a meta_query to exclude all pages with the custom field _wp_page_template set to bedankt. Remember, WordPress saves the template assigned to a page as a hidden custom field called _wp_page_template With … Read more

Getting post data from private page

setup_postdata takes a post object of type \WP_Post, but you’re passing it a WP_Query instead e.g. global $post; setup_postdata( $post ); Thankfully the solution is trivial, when you call the_post, it sets up the current post data for you, so removing that line is all you need to do. The second issue is that WP_Query … Read more

Get post according to current taxonomy

Try this for WP_Query $args = array( ‘post_type’ => ‘example’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘identite’, ‘field’ => ‘ID’, ‘terms’ => $term->term_id ) ), );// end args OR $args = array( ‘post_type’ => ‘example’, ‘tax_query’ => array( ‘relation’ => ‘AND’, array( ‘taxonomy’ => ‘identite’, ‘field’ => ‘ID’, ‘terms’ => array($term->term_id) ) … Read more

MySQL variable in query

See the documentation for $wpdb->prepare(). You need to pass a String, but you’re typing set @csum directly in the parameter. Your code should look like this: if ( is_user_logged_in() ) { $user = wp_get_current_user(); $balance = $wpdb->query( $wpdb->prepare( “SET @csum := (SELECT current_balance FROM exp_ten WHERE tenant_number=%d); SELECT tenant_number, transaction_amount, (@csum := @csum + transaction_amount) … Read more

How to export current year posts from WordPress?

The core version of WordPress (i.e. with no plugins installed) has export functionality built-in. You will find the export feature in the main WordPress admin menu in the Tools section. There are three options available. The first option backs up all content including posts, pages, comments, custom fields, categories and tags. Alternatively, you can choose … Read more

add_query_arg() and empty variables inside

You can instantiate your array before-hand, optionally populate it, and pass it to the add_query_arg() function like so: $url_query_args = array(); if( isset( $search ) ) { $url_query_args[‘search’] = $search; } if( isset( $category ) ) { $url_query_args[‘category’] = $category; } if( isset( $filter ) ) { $url_query_args[‘filter’] = $filter; } esc_url( add_query_arg( $url_query_args, ‘/site’ … Read more