WP_Query with LIKE returns strange query

IN works quite fine for comparison though
array(

                'key' => 'customdata',                  'value' => $  arraydata,                  'compare' => 'IN'              ), 

but when i try below with LIKE it returns strange result with long codes and also no record is found against it. Any help much appreicated

array(

                'key' => 'customdata',                  'value' => $  arraydata,                  'compare' => 'LIKE'              ) 

$ loop = new WP_Query($ loopArray); echo “Query: {$ loop->request}”;

Get x numbers of a woocommerce category products using Wp_Query

Is possible to show some woocommerce products inside a swiper slider? I want to create a slider that will show some “featured” products on the home page. For now I have a cpt that is achieving this, but I don’t know how to link them to the products that I will add to woocommerce. So I want to replace the cpt with a query to get an x number of products from woocommerce products and put them into the slider. Any help will be appreciated.

The code I’m using now is this

<div class="row featured-row" <?php $  featured = new WP_Query( ['post_type' => 'featured', 'order' => 'ASC', 'posts_per_page' => 3] ); ?> <?php $  i = 0; ?> <?php if( $  featured->have_posts() ): while( $  featured->have_posts() ): $  featured->the_post(); ?> <?php #$  class = get_post_meta( get_the_ID(), 'class', true); ?> <?php if( $  i === 1 ): ?>   <div class="col-md-6 col-lg-6 d-none d-sm-none d-md-block featured-desc">     <h2 class="featured-title-right text-right"><?php the_title(); ?></h2>     <p class="featured-excerpt-right text-right"><?php echo get_the_excerpt(); ?></p>   </div>   <div class="col-md-6 col-lg-6 text-center d-none d-sm-none d-md-block featured-img">     <img class="img-fluid" src="<?php the_post_thumbnail_url(); ?>">   </div> <?php else: ?>   <div class="col-md-6 col-lg-6 text-center d-none d-sm-none d-md-block featured-img">     <img class="img-fluid" src="<?php the_post_thumbnail_url(); ?>">   </div>   <div class="col-md-6 col-lg-6 d-none d-sm-none d-md-block featured-desc">     <h2 class="featured-title"><?php the_title(); ?></h2>     <p class="featured-excerpt"><?php echo get_the_excerpt(); ?></p>   </div> <?php endif;?> <?php $  i++; ?> <?php endwhile; ?> <?php endif; wp_reset_postdata(); ?> </div>  

How to add another parameters to WP_Query?

I need to do something like that:

        $  postsOrder = get_sub_field('posts-ordering');          if ($  postsOrder = 'post_views_count') {             $  queryPopular = array (                 'meta_key' => 'post_views_count',                 'orderby' => 'meta_value_num',             );         }          $  query = new WP_Query(             array(             'posts_per_page' => $  postsCount,             'post_type' => $  postsType->name,             'order' => 'DESC',             'orderby' => $  postsOrder,             'taxonomy' => $  postsTaxonomy,             $  queryPopular             ),         ); 

The point is that if $ postsOrder is equal ‘post_views_count’, then in $ query should be added two another parameters. How to do it right?

Why does using WP_Query inside a shortcode in an elementor page cause the arguments for WP_Query to get malformed?

I am trying to embed a custom WP_Query inside a shortcode I have activated on one of my pages (created in Elementor). I have a Custom Post Type called ‘inspector-profiles’, and for some reason when I add that to my $ args array, it gets either not honored by WP, or it is overwritten by something else.

I cannot see what is causing an overwrite if anything.

The code is this, so far:

private function isInspector() {     if (is_user_logged_in()) {         $  user = wp_get_current_user();         return in_array('general_inspector', (array)$  user->roles);     }     return false; }  public function sc_inspectorProfileData() {     global $  wpdb;     $  user = \wp_get_current_user();       // WP_Query arguments     $  args = array(         'post_type'              => 'inspector-profiles',         'post_status'            => 'publish',         'author'                 => $  user->ID     );       // The Query     echo '<pre>';      $  myq = new \WP_Query( $  args );      print_r($  myq->request);      if ($  myq->have_posts()) {         while ($  myq->have_posts()) {             $  myq->the_post();             print_r($  myq->post);             wp_reset_postdata();             wp_reset_query();         }     }      echo '</pre>'; } 

When I create the arguments for WP_Query above, the $ args array looks fine prior to running the query. When I run the query, I immediately spit out the generated SQL query, and it looks like this:

SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_author IN (1) AND wp_posts.post_type IN ('post', 'page', 'attachment', 'memberpressproduct', 'memberpressgroup', 'mpdl-file', 'ht_kb') AND ((wp_posts.post_status = 'publish')) ORDER BY wp_posts.post_date DESC LIMIT 0, 200

My specified post_type is not even in that list. What am I doing wrong? I have tried using instances of get_posts(), using the WP_Query object, and some stuff that has been deprecated even.

How to sort by multiple values in a nested WP_Query

I am displaying courses, enrollment, along with rooms whose capacities are greater than or equal to the enrollment. This query works, except the ‘order’ => ‘DESC’ for courses, and ‘orderby’ => ‘meta_value_num’.

Currently, the courses are listed by title, but ascending. And, the rooms are not ordered at all. Can anyone tell me what I’m doing wrong?

$  courses = new WP_Query( array( 'post_type' => 'courses', 'posts_per_page' => '-1', 'orderby' => 'title' , 'order' => 'DESC' ) );   if ( $  courses->have_posts() ) {   while ( $  courses->have_posts() ) {     $  courses->the_post();           $  enr = get_post_meta(get_the_ID(), 'course_enrolled' , true);          $  cname = get_the_title();           $  rooms = new WP_Query(                   array(                   'posts_per_page' => -1,                   'post_type' => 'rooms',                   'meta_query' => array(                         array(                         'key' => 'room_capacity',                         'posts_per_page' => '-1',                         'type' => 'NUMERIC',                         'value' => $  enr,                         'compare' => '>=',                         //the below ordering part doesn't function as expected                         'order' => 'DESC',                         'orderby' => 'meta_value_num'                          )                       )                     )           );           if ( $  rooms->have_posts() ) {             while ( $  rooms->have_posts() ) {                 $  rooms->the_post();                   $  rname = get_the_title();                 $  cap = get_post_meta(get_the_ID(), 'room_capacity' , true);                  echo 'cname: ' . $  cname . ' ' . 'enrolled: ' . $  enr . 'rname: ' . $  rname.  'capacity: ' . $  cap . '<br/>';                }             }       } } else {     echo "Loop not working";   }     wp_reset_postdata(); 

Foreach result into WP_query

I know it may sound very strange as a question, but I would like to know if it is possible to insert the result of a foreach in WP_query

How:

I would like to avoid doing the maintenance manually that every custom post type created must add the name of the custom post type to the post_type query, to be clear:

'post_type' => array('CUSTOM_POST_TYPE_ONE,CUSTOM_POST_TYPE_TWO'), 

but instead get me the whole list of custom post types:

<?php $  args = array(     'public'   => true,     '_builtin' => false );  $  output = 'names'; // 'names' or 'objects' (default: 'names') $  operator = 'and'; // 'and' or 'or' (default: 'and')  $  post_types = get_post_types( $  args, $  output, $  operator ); echo $  post_types; if ( $  post_types ) { // If there are any custom public post types.      echo '<ul>';      foreach ( $  post_types  as $  post_type ) {         echo '<li>' . $  post_type . '</li>';     }      echo '<ul>';  } ?> 

and insert it into:

'post_type' => 

so that every time I create a custom post type I get a dynamic query

Numbered Pagination Showing The Same Posts After Altering WP_Query

I think the title sums the problem up, but I’ll explain more with the code below.

As you can see, I’m trying to start the loop from the second latest post for some theme reasons which forced me to alter the main loop, and I used the parameter offset to make that work, and everything worked just fine, but after I moved on with the development, I started developing the numbered pagination, and finally got surprised with my altered loop showing the same posts in every page.

I chose to use WP_Query and not touch query_posts(), as it’s simple and faster, now I’m stuck with this problem, and tested everything and didn’t work.

Here is the altered loop using class WP_Query:

<?php     $  paged = get_query_var( 'page' ) ? get_query_var( 'page' ) : 1;     $  args = array(        'offset' => 1,        'post_type'  => 'post',        'paged'      => $  paged     );     $  offset_loop = new WP_Query( $  args ); ?> <?php if ( $  offset_loop->have_posts() ): ?>     <?php while ( $  offset_loop->have_posts() ): $  offset_loop->the_post(); ?>         <div class="blog_loop_container">             <article class="blog_post <?php post_class(); ?>" id="post-<?php the_ID(); ?>">                 <div class="post_thumbnail"><?php the_post_thumbnail( 'medium_large' ); ?></div>             </article>         </div>     <?php endwhile; ?>      <?php // wp_reset_postdata(); ?>     <?php echo thegreatguy_pagination(); ?> <?php endif; ?> 

And here is the pagination function i’m using :

function thegreatguy_pagination() {     global $  wp_query; // Calling The Global Variable Representing WP_Query Class.     $  totalPages = $  wp_query->max_num_pages; // Retrieves The Maximum Pages The Blog has.     $  currentPage = max( 1, get_query_var( 'paged' ) ); // Retrieves The Number Of The Current Page.      if ( $  totalPages > 1 ) { // Check For More Pages To Return.         return paginate_links( array(             'format'        => 'page/%#%',             'base'          => get_pagenum_link() . '%_%',             'current'       => $  currentPage,             'prev_text'     => 'Previous',             'next_text'     => 'Next'         ) );     } } 

Hide some Category in wp_query

I have created in new custom post type. Now I want to show all the posts in one page. But I want to hide in some category’s post in that. How could I do that?

                                $  args_post = array(                                     'post_type' => 'products',                                      'posts_per_page' => -1,                                     'post_status' => 'publish',                                      'orderby' => 'publish_date',                                      'order' => 'ASC',                                     'tax_query' => array(array(                                          'taxonomy' => 'product_categories',                                          'field' => 'slug',                                          'terms' => 'new_term'                                         )                                     )                                 ); 

Exclude authors IDs from WP_Query

I am using this code, trying to exclude specific authors from WP_Query, however the author IDs in the array are not being excluded. Any ideas please?

<?php $  args  = array('meta_query' => array(array('who' => 'authors')),array( 'author__not_in' => array(10, 3, 4)) );$  site_url = get_site_url();$  wp_user_query = new WP_User_Query($  args);$  authors = $  wp_user_query->get_results(); ?>