Differentiate Nested WP_Query from Parent

You could check if the current post ID is the same as the ‘queried object’ ID, which is whichever post the current URL represents, and is separate from the current post within the loop. If both those IDs are the same then you can assume that the current content being filtered is for the content … Read more

woocommerce search by sku and title ajax

Pls Try this code if(is_numeric($search_keyword)){ $args = array( ‘posts_per_page’ => 3, ‘post_type’ => ‘product’, ‘meta_query’ => array( array( ‘key’ => ‘_sku’, ‘value’ => $search_keyword, ‘compare’ => ‘LIKE’ ) ) ); } else if(is_string($search_keyword)){ $args = array( ‘s’ => $search_keyword, ‘post_type’ => ‘product’, ‘post_status’ => ‘publish’, ‘ignore_sticky_posts’ => 1, ‘posts_per_page’ => 3, ‘orderby’ => $ordering_args[‘orderby’], ‘order’ … Read more

Continue or break the while loop

‘break’ is the right keyword… code structure below, no custom query needed if used in a standard template. <?php $posts_per_first_section = 6; //how many posts you want to show in the first section// if ( have_posts() ) : ?> <!– opening html for first loop –> <?php /* Start the Loop */ while ( have_posts() … Read more

How to load a script code only in posts?

In the active theme, functions.php file or in your plugin, function load_scripts() { if ( is_singular( ‘post’ ) ) { // Load the Javascript wp_enqueue_script( string $handle, string $src=””, array $deps = array(), string|bool|null $ver = false, bool $in_footer = false ); } } add_action( ‘wp_enqueue_scripts’, ‘load_scripts’ );

How remove trashed WooCommerce orders from wc_get_orders() result?

Use Wp_Query instead it will give you the option to get data with status. $args = array( ‘post_type’ => ‘shop_order’, ‘posts_per_page’ => ‘-1’, ‘post_status’ => array(‘publish’, ‘pending’, ‘draft’, ‘auto-draft’, ‘future’,’private’, ‘inherit’, ‘trash’) ); $my_query = new WP_Query($args); $orders = $my_query->posts; echo “<pre>”; print_r($orders); echo “</pre>”; it will display All of your order. hope this will … Read more

Custom route and query

There are 3 issues with your code: The proper syntax of registering your custom REST API route, is as follows: register_rest_route( $namespace, $base_URL, $args, $override ); So: register_rest_route( ‘boss/v1’, ‘/latest-quiz-results’, array( ‘methods’ => ‘GET’, ‘callback’ => ‘get_latest_quiz_results’ ) ); Consult the reference for more information. In the get_latest_quiz_results(), $wpdb is not defined because you’re missing … Read more