I need to exclude from a query a category and a few custom taxonomies

Change ‘relation’ => ‘OR’ to ‘relation’ => ‘AND’ to apply both exclusions to all posts returned. It may seem counterintuitive, but a post that satisfies one of the exclusions will be included even if it doesn’t satisfy the other. EDIT From the code linked in your comment below, this is the query being generated: SELECT … Read more

How to get main menu only with wp_nav_menu

You can use the depth parameter like this: wp_nav_menu( array( ‘menu’ => ‘header-uk’, ‘menu_id’ => ‘nav’, ‘menu_class’ => ‘sitemap’, ‘fallback_cb’ => false, ‘depth’ => 1, ) ); Or if what you want to do is grab all items to create your own loop/output you can do that as well. Example: if ( ( $locations = … Read more

How to get current page nearest parent id?

try this. global $post; // if outside the loop $page_object = get_queried_object(); $page_id = get_queried_object_id(); // Get current page id $args = array( ‘sort_order’ => ‘ASC’, ‘sort_column’ => ‘post_title’, ‘hierarchical’ => 1, ‘exclude’ => ”, ‘include’ => $page_id, ‘meta_key’ => ”, ‘meta_value’ => ”, ‘authors’ => ”, ‘child_of’ => 0, ‘parent’ => -1, ‘exclude_tree’ => … Read more

Unlimited Page Sitemap Link

You are most probably exceeding the maximum execution time when trying to retrieve 7000 posts/products, or specifically more than 2000 posts/products. To be quite honest with you, 7000 posts/products (or even just a list of posts/products) all packed in one single page is not only going to drive you crazy, but anyone visiting your site. … Read more

WordPress query portfolio posts

You can simply just add the cat or category_name parameter to your query. When using cat, you should use the category ID, and should you use category_name, it should be the slug of the category, not the name. Change <?php $tarali_query = new WP_Query(‘posts_per_page=”.$nbmax.”&ignore_sticky_posts=1&paged=’.$paged); ?> to <?php $tarali_query = new WP_Query(‘posts_per_page=”.$nbmax.”&cat=CATID&ignore_sticky_posts=1&paged=’.$paged); ?> For futher reading: … Read more

When WP_Query only returns 1 post, how do I automatically redirect to that post?

You can do this by checking the number of results returned by your query. Try this. <?php $rawfiltertag = get_post_meta( $post->ID, ‘_cmb_client_name’, true ); $filtertag = sanitize_title( $rawfiltertag ); // wp_query arguments $args = array ( ‘post_type’ => ‘post’, ‘meta_query’ => array( array( ‘key’ => ‘_cmb_client_target’, ‘value’ => $rawfiltertag ) ) ); // the query … Read more

Displaying Event within two given time frames

Querying on the meta data table is slow, and as since it’s also used for general data, you need to be careful about your date format if you’re storing dates there. For instance, with dmY format: 01112014 ( 1st November 2014 ) 11012014 ( 11th January 2014 ) 12052014 ( 12th May 2014 ) is … Read more

Max Posts and Memory Limit

For me, this was happening b/c of post meta cache issues. This article suggested code which solved my issue – and apparently many other’s as well. https://junaid.dev/wordpress-admin-fix-fatal-error-allowed-memory-size-error/?unapproved=369&moderation-hash=bd9064ea40d413150d8a42599c13f4f5#comment-369 Here is the code he provides: function jb_pre_get_posts( WP_Query $wp_query ) { if ( in_array( $wp_query->get( ‘post_type’ ), array( ‘my_post_type_1’, ‘my_post_type_2’ ) ) ) { $wp_query->set( ‘update_post_meta_cache’, false … Read more