WordPress Related Posts by Title and Category

Probably the simplest approach is to combine the category query with a search query (untested): $cat_query = new WP_Query( array( ‘cat’ => $cat_id, ‘post__not_in’ => array( get_the_ID() ), ‘no_found_rows’ => false, ‘posts_per_page’ => 6, ) ); $title_query = new WP_Query( array( ‘post__not_in’ => array( get_the_ID() ), ‘s’ => get_the_title(), ‘no_found_rows’ => false, ‘posts_per_page’ => 6, … Read more

Show category name in category.php when posts assigned to multiple categories

For the heading on a category archive use either: the_archive_title(); Or: single_term_title(); The first one can be used on the template for any archive, while the second should only be used on category, tag, or taxonomy archive templates. You shouldn’t need to get anything from any of the individual posts. They may have other categories … Read more

WP Query filtering by custom category not showing all relevant posts

@jacob-peattie answered the question in his comment – I used the wrong key to set the number of posts my query generates. Swapping numberposts with posts_per_page solved the issue. Here’s the final query: @php $cats = get_sub_field(‘reviews_category’); // gets the custom field categories $args = array( ‘post_type’ => ‘testimonials’, ‘posts_per_page’ => -1, // this line … Read more

Custom post type category pages pagination returns 404

The issue I’m having is with the pagination on category pages, e.g. /release-notes/category/upgrades/, where pages 2 and beyond return a 404. That’s because your custom rewrite rule does not support paged requests, i.e. it’s missing the RegEx ( regular expression pattern ) and query for the paged parameter. So you can either add another rewrite … Read more

Remove product meta from single product page

If the code you provided is not working for other themes, it’s possible that the hooks or actions used by those themes are different. To remove product categories from the single product page using PHP, you can try the following code: function remove_product_meta() { remove_action( ‘woocommerce_single_product_summary’, ‘woocommerce_template_single_meta’, 40 ); } add_action( ‘init’, ‘remove_product_meta’ ); This … Read more

Count post with tags within one category?

Yes it is possible to count the posts with certain tags within a particular category. You can achieve this by using a combination of wp functions like WP_Query to retrieve posts and get_terms to retrieve the tags within the specified category. <?php $category_slug = ‘donotallowpost’; $term_slugs = [ ‘cat’, ‘bird’, ‘chinchilla’, ‘dog’, ‘ferret’, ‘hamster’, ‘horse’, … Read more

How to get a list of all posts and their categories?

If you want to export the data to a CSV or JSON file directly from the SQL query, you can use the MySQL INTO OUTFILE clause. SELECT wpd9_posts.post_title, GROUP_CONCAT(wpd9_terms.name) AS categories FROM wpd9_posts LEFT JOIN wpd9_term_relationships ON (wpd9_posts.ID = wpd9_term_relationships.object_id) LEFT JOIN wpd9_term_taxonomy ON (wpd9_term_relationships.term_taxonomy_id = wpd9_term_taxonomy.term_taxonomy_id) LEFT JOIN wpd9_terms ON (wpd9_term_taxonomy.term_id = wpd9_terms.term_id) WHERE … Read more

Fetch Post Category

If you want to display and fetch all post categories that have posts associated with them and display them in a dropdown list in the WP admin panel, try below the code add in code to your themes functions.php file or in a custom plugin. function get_categories_with_posts() { // Get all categories that have posts … Read more