How to explode single string IF it’s used in shortcode

I have a shortcode that works to display posts from specific categories, or a single post based on the post slug. I’m having trouble figuring out how to get it to display multiple posts based on their slugs though. I know I need to use explode, but I can’t seem to get it right.

Here’s the current working code:

add_shortcode( 'latest_post', 'latest_post_query_shortcode' ); function latest_post_query_shortcode(  $  atts ) {     ob_start();     $  atts = shortcode_atts( array(             'posts_per_page' => '',             'category' => '',             'offset' => '',             'post' => '',     ), $  atts );      $  args = array(             'post_type'     => 'post',             'post_status'   => 'publish',             'posts_per_page'=> $  atts['posts_per_page'],             'offset'             => $  atts['offset'],         );              // Add category if not empty     if ( ! empty ( $  atts['category'] ) ) {         $  args['tax_query']  = array(                  array(                     'taxonomy'  => 'category',                     'field'     => 'slug',                     'terms' => $  atts['category'],                 ),              );           }          // Add post if not empty     if ( ! empty ( $  atts['post'] ) ) {         $  args['name']  = $  atts['post'];     }         $  string = '';              // The Query     $  query = new WP_Query( $  args );       // The Loop     if ( $  query->have_posts() ) { ?>         <section class="recent-posts clear">         <?php while ( $  query->have_posts() ) : $  query->the_post() ; ?>             <article id="post-<?php the_ID(); ?>" <?php post_class( 'left' ); ?>>                  <?  echo '<a href="' . get_permalink( $  _post->ID ) . '" title="' . esc_attr( $  _post->post_title ) . '">';                     echo get_the_post_thumbnail( $  _post->ID, 'large' );                     echo '</a>';                     echo '<h2><a href="' . get_permalink( $  _post->ID ) . '" title="' . esc_attr( $  _post->post_title ) . '">';                     echo get_the_title( $  _post->ID);                     echo '</a></h2>';                  ?>             </article>         <?php endwhile;          wp_reset_postdata();?>           </section>                   <?php          $  clean = ob_get_clean();         return $  clean;           } } 

I tried adding:

'name' => explode( ', ', $  post), 

inside

$  args = array( 

but that didn’t return anything when I tried specifying two slugs, for example: [latest_post post="almond-cake, coconut-pie"] (If I use either one of those, it works, but not both.)

Additionally once I added the explode, it game me this warning everywhere else the shortcode was used:

Warning: trim() expects parameter 1 to be string, array given…

Convert php into shortcode

Kindly someone convert this php code into shortocode. I am unable to do this. Thanks in advance!

<?php if ( $  type == 'credit' ) { <p><?php _e( "Thank you for using your nedvil wallet.", 'woo-wallet' ); ?> <?php echo wc_price( $  amount, woo_wallet_wc_price_args($  user->ID) ); ?> <?php _e( 'has been credited to your wallet.', 'woo-wallet' ); ?> <?php _e( 'Current wallet balance is', 'woo-wallet' ); ?> <?php echo woo_wallet()->wallet->get_wallet_balance( $  user->ID ); ?></p> <?php } ?> <?php if ( $  type == 'debit' ) { ?>     <p><?php _e( "Thank you for using your wallet.", 'woo-wallet' ); ?> <?php echo wc_price( $  amount, woo_wallet_wc_price_args($  user->ID) ); ?> <?php _e( 'has been debited from your wallet.', 'woo-wallet' ); ?> <?php _e( 'Current wallet balance is', 'woo-wallet' ); ?> <?php echo woo_wallet()->wallet->get_wallet_balance( $  user->ID ); ?></p> <?php } <?php 

Get/create the parent taxonomy by using shortcode in woocommerce?

How would I get/create the parent taxonomy by using shortcode in woocommerce?

My product categories should be like:

– Food

— Fruits

— Healthy Fruits
— Organic Fruits

— Meat

— Pork
— Lamb
— Beef

For example, I would like to display “Fruits” when user at the “Healthy Fruits” product archive page.

Two Pagination in One page with shortcode

I create a shortcode to show posts by category with attributes. I want to show 2 separate categories with a separate shortcode in one page but the pagination connected.

If I change pagination in the first shortcode, also change pagination in the second shortcode. Basically it same shortcode but different attributes.

here my code:

add_shortcode('new-blog-grid','new_blog_grid'); function new_blog_grid($  atts){     ob_start();     extract( shortcode_atts(                array(                        'count' => '',                        'pagination' => '',                        'category' => ''                                   ),                $  atts        ));      if ($  count) {$  post_count = $  count; } else {$  post_count = 12; }     $  paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;         $  args = array(         'post_type' => 'post' ,         'posts_per_page' => $  post_count,         'post_status' => 'publish',         'paged' => $  paged,         'ignore_sticky_posts' => true,         'order' => 'DESC',          'orderby' => 'date'     );      if($  category != null) {         $  args['category_name'] = $  category;     }       $  query = new WP_Query($  args);      echo '<div class="listing-blog-grid">';          if ($  query->have_posts()) {             while ($  query->have_posts()) {                 $  query->the_post();                  $  thumbs = get_the_post_thumbnail_url();                 $  terms = get_the_terms(get_the_ID(),'category');                 //print_r($  terms);                 ?>                 <div class="listing-blog-list" onclick="location.href='<?php the_permalink()?>'" style="cursor:pointer;">                     <div class="listing-blog-wrapper">                         <div class="listing-blog-header">                             <div class="listing-blog-images" onclick="location.href='<?php the_permalink()?>'" style="background: url('<?php echo $  thumbs; ?>') no-repeat center; background-size:cover; background-color: rgba(0, 0, 0, 0.5);"></div>                         </div>                         <div class="listing-blog-content">                             <div class="listing-date"><?php the_time( 'j F Y ' ); ?></div>                                                       <?php the_title( '<h4 class="entry-title"><a href="' . esc_url( get_permalink() ) . '" rel="bookmark">', '</a></h4>' ); ?>                         </div>                      </div>                               </div>         <?php   }         }          else {             echo "Geen berichten van deze auteur.";         }      echo '</div>';      if ($  pagination == 'yes') {  ?>                   <div class="pagination">             <?php             $  total_pages = $  query->max_num_pages;             $  current_page = max( 1, get_query_var('paged'));              if ($  current_page != 1){                  echo '<a href="/new-landing-page/"><img src="/wp-content/uploads/2019/06/paginatie-B-left.png"></a>';             }              if ($  total_pages > 1){                        echo paginate_links(array(                     'base' => get_pagenum_link(1) . '%_%',                     'format' => '/page/%#%',                     'current' => $  current_page,                     'total' => $  total_pages,                     'prev_text' => __(''),                     'next_text' => __(''),                 ));             }             if ($  current_page != $  total_pages){                 echo '<a href="/new-landing-page//page/'.$  total_pages.'"><img src="/wp-content/uploads/2019/06/paginatie-B.png"></a>';             }               ?>                                </div>          <?php }     return ob_get_clean();     wp_reset_query(); } 

so shortcode I put in one page

cat: media

[new-blog-grid count=5 pagination=yes category=pr-media] 

cat: stories

[new-blog-grid count=5 pagination=yes category=stories] 

I need it became seperate pagination, is there any way to achieve that.

Change layout of [products] shortcode

I would like to display additional products on my simple product pages.I am using the shortcode like so in the simple products short description.

[products ids="2113"] 

The problem with this is the layout of the resulting loop. Is there a way to customise the layout to just supply the Name – Price – “Add to Cart” Button in a single line. Almost like its a variation option. Currently, I don’t think this is possible with just CSS.

Thanks

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.

WooCommerce Multi-Currency shortcode not working

I’ve installed and activated WooCommerce Multi-Currency plugin. I’m still on the free version but I with that I can add two currencies. This works fine if I try to add the widget to the footer or some other widget area. But I need to have this in the top bar and it seems OceanWP does not have a widget area for that.

So I tried to add it with the shortcode [woocommerce-currency-selector format="{{code}}: {{name}} ({{symbol}})"]. But the shortcode just shows up as text. I’ve tried adding it with echo do_shortcode as well but it still shows up as text.

What am I missing?