How to compare Event period with Week period using get_posts(), meta_query, relation and compare

To be able to do this your post meta values need to be strings in a valid date format, e.g. 2022/01/31 for January 31st 2022. Note I used ISO standard timestamp format with the biggest value first, then everything descending, and avoided using a regional value such as 31/1/2022 from the UK, or 1/31/2023 from … Read more

Equivalent of url_to_postid() for non-post URLs?

The simplest solution is to get all the existing rewrite rules, match the requested URl to one of them, and then convert it into a query. Like so: // Get all the rewrite rules global $wp_rewrite; $url_path = “2020/04/test-post”; // Or “tag/whatever” or “feed/atom” etc // Match the URL against WordPress rewrite rules $rewrite_rules = … Read more

How to show related posts by detecting the current category?

The question has already been asked and the answer has been posted too, How to display related posts from same category? Add this code inside your single.php after a loop wherever you want to show related post, <?php $related = get_posts( array( ‘category__in’ => wp_get_post_categories($post->ID), ‘numberposts’ => 5, ‘post__not_in’ => array($post->ID) ) ); if( $related … Read more

get_posts() function does not honor correct post type

This could be caused by a pre_get_posts action that doesn’t have the proper conditions/checks. For example: add_action( ‘pre_get_posts’, function( $query ) : void { if ( is_post_type_archive( ‘tribe_events’ ) ) { $query->set( ‘post_type’, ‘tribe_events’ ); } } ); Likewise if this was a page template and not a post archive they might have this in … Read more

Operator ‘AND’ in the get_posts() function’s tax_query terms not working

Try adding include_children parameter as false to your first example (tested): $args = array( ‘post_type’ => ‘workshops’, ‘posts_per_page’ => -1, ‘fields’ => ‘ids’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘workshop_categories’, ‘field’ => ‘slug’, ‘terms’ => array( ‘crafts’, ‘jewellery’ ), ‘operator’ => ‘AND’, ‘include_children’ => false, ) ) ); $posts = get_posts( $args ); Unfortunately I … Read more

WordPress duplicating posts from single loop

Unless I’ve mis-interpreted what you are trying to accomplish, you added the foreach loop and you don’t need it. Having it run while inside a while loop seems to be duplicating your intentions. Remove the foreach loop altogether, delete the first wp_reset_postdata();, and un-comment the 2nd one: <div id=”carouselTestimonial” class=”carousel slide” data-bs-ride=”carousel”> <div class=”carousel-inner”> <?php … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)