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

Get all products which have both product category

Set include_children to false in the tax_query. $args = array( ‘post_type’ => array( ‘product’, ‘product_variation’ ), ‘tax_query’ => array( array( ‘taxonomy’ => ‘product_cat’, ‘field’ => ‘slug’, ‘terms’ => array( ‘shop’, ‘cat1’ ), ‘include_children’ => false, ‘operator’ => ‘AND’, ) ) ); See https://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

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

Echo a hierarchical list of post data from custom fields

A little example, based on get_posts and get_post_meta. $locations = get_posts( array(‘post_type’ => ‘locations’, ‘posts_per_page’ => -1, ‘post_status’ => ‘publish’ ); echo ‘<ul>’; foreach ($locations as $location) { $location_city = get_post_meta($location->ID, ‘city’, true); $location_state = get_post_meta($location->ID, ‘state’, true); $location_address = get_post_meta($location->ID, ‘address’, true); echo ‘<li>’ . $location_city; echo ‘<li>’ . $location_state . ‘</li>’; echo ‘<li>’ … 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