Checkbox onclick filtering on the same page

Try this script: But before that, the form‘s method should remain as GET. And in the form markup/HTML, remove the onchange=”this.form.submit()” from all the checkbox fields. Then add a standard submit button to the form; example: <input type=”submit” value=”Go” /> [EDIT] The submit button is not necessary. I’ve updated the script so that when selecting … Read more

Increase offset while looping

Yup. What you’re looking for is a smart “counter”. In actuality, your issue is this: You’re trying to avoid duplicate posts. Here’s the popular method to do it. In every file that you run a query, you must add this code: global $duplicated_posts; $args = [ ‘post_type’ => ‘post’, ‘post__not_in’ => $duplicated_posts ]; $query = … Read more

Order by empty custom field

There are two solutions for that: 1. Make sure that all posts have that field set. You can do this easily – just use save_post hook and set it to default value. (You should also add default values for already existing posts that don’t have that field set.) 2. Use a little bit modified query … Read more

How to get related tags based on a category?

You can get such tags using plain SQL query: global $wpdb; $wpdb->get_results( $wpdb->prepare( “SELECT tags.*, COUNT(tags_rel.object_id) as posts_count FROM {$wpdb->prefix}terms tags INNER JOIN {$wpdb->prefix}term_taxonomy tags_tax ON (tags_tax.term_id = tags.term_id) INNER JOIN {$wpdb->prefix}term_relationships tags_rel ON (tags_tax.term_taxonomy_id = tags_rel.term_taxonomy_id) INNER JOIN {$wpdb->prefix}posts posts ON (tags_rel.object_id = posts.ID) INNER JOIN {$wpdb->prefix}term_relationships cats_rel ON (posts.ID = cats_rel.object_id) INNER JOIN … Read more