WC displaying products from category

For custom taxonomies, including Product Categories, you should use the tax_query argument: $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 12, ‘tax_query’ => array( array( ‘taxonomy’ => ‘product_cat’, ‘terms’ => 40, ), ), );

Remove a specific category ID from related post

from looking at https://developer.wordpress.org/reference/functions/wp_get_post_terms/ and https://developer.wordpress.org/reference/classes/wp_term_query/__construct/ for corresponding parameters, i.e. the ‘exclude’ parameter and https://developer.wordpress.org/reference/functions/get_category_by_slug/ to get the category ids from their slugs. it might work when you replace this line in your code: // Get the taxonomy terms of the current page for the specified taxonomy. $terms = wp_get_post_terms( get_the_ID(), ‘category’, array( ‘fields’ => … Read more

Check on which page specific result exist

You can select this term_id from the DB and add row number column in SQL Query and then you can calculate in which page it should be. For example: global $wpdb; $wanted_term = $wpdb->get_row(“SELECT terms.* FROM ( SELECT @rownum := @rownum + 1 AS rownum, t.*, tt.taxonomy FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS … Read more

How to create a WordPress Post Filter that users can use to filter posts by year?

I’m pretty sure you haven’t even try to search for solution… If you did, then I’m pretty sure you would came to this Codex page, where you can find this code: <select name=”archive-dropdown” onchange=”document.location.href=this.options[this.selectedIndex].value;”> <option value=””><?php echo esc_attr( __( ‘Select Month’ ) ); ?></option> <?php wp_get_archives( array( ‘type’ => ‘monthly’, ‘format’ => ‘option’, ‘show_post_count’ => … Read more

WP_Query won’t retrieve raw HTML?

WP_Query object contains FULL content of posts/pages retrieved from database. No HTML tags are being removed. Therefore, the following statement in your question: It looks like WP_Query is parsing the HTML and then displaying what is left. is not true. If you use, in your code, the_content() instead of the_excerpt() function, you’ll see that all … Read more

Custom query based on meta key – Reduce three states to two in results?

This can be done by providing a “default” value to the ORDER BY statement. Try adding this before your call new WP_Query($args);: $setDefaultOrderby = function($statement) { return str_replace(‘wp_postmeta.meta_value’, “COALESCE(wp_postmeta.meta_value, ‘false’)”, $statement); }; add_filter(‘posts_orderby’, $setDefaultOrderby); and this after it: remove_filter(‘posts_orderby’, $setDefaultOrderby); Change the ‘false’ with whatever the default value is that you need. I am using … Read more

query offset countdown by 2 each day?

There could be several approaches but here is one, which comes in my mind. Steps with code example: Initially, store the count in Database using Options API like this: update_option(‘offset_count’, 1000); $current_date = date(“d”); update_option(‘last_countdown_date’, $current_date); Before querying the post, retrieve both values from DB, like this: $offset_count = get_option( ‘offset_count’ ); $last_date = get_option( … Read more