while converting my custom posts into shortcode not displaying on a page

Viewed 25

I'm using this code for converting the shortcode : on my shortcode.php file: my webiste is up and running buy my shortcode is not woking on my other pages:

function service_shortcode( $atts ){
    ob_start();
    $query = new WP_Query(array(
        'post_type'     => 'services',
        'post_per_page' => 6
    ));

    if($query -> have_posts()){ ?>
    <div class="container">
            <div class="row section-title">
                <div class="col-md-6 text-right">
                    <h3><span>who we are?</span> our services</h3>
                </div>
                <div class="col-md-6">
                    <p>Lorem Ipsum is simply dummy text of the printing and 
                      typesetting industry typesetting industry.d </p>
                </div>
                </div>
                <div class="row">
                <?php
                while ( $query -> have_posts() ) : $query -> the_post();
                ?>

                    <div class="col-lg-4 col-md-6">
                        <!-- Single Service -->
                        <div class="single-service">
                                <i class="<?php the_field('service_icon'); ?>"></i>
                                <h4><?php the_title(); ?> </h4>
                                <p><?php the_content(); ?></p>
                        </div>
                    </div>

                <?php
                endwhile;
                wp_reset_postdata();
                ?>  
                </div>
            </div>l
        </div>
    <?php $myvariable = ob_get_clean();
        return $myvariable;
    }
    }
    add_shortcode( 'service-short' , 'service_shortcode');

*I have a custom post type called service inside that i'm using ACF(advance custom field) 'service-icon' for making it more user friendly. It works fine when i'm use it in my template-home file by hand coded. When converting it as shortcode on other pages it not showing any results or any error. my custom post type code is for service custom post type down below: *

   //services custom post type
    register_post_type( 'services', array(
        'labels' => array(
            'name' => __('Services' , 'sepleenWp'),
            'singular_name' => __('Service' , 'sepleenWp')
        ),
        'public' => true,
        'show_ui' => true,
        'supports' => array('title', 'editor', 'custom-fields'),
        'menu_position'       => 12,
        'menu_icon'           => 'dashicons-embed-photo',
        'show_in_rest' => true
    ));

On my template-home.php the custom post type works as fine

    <div class="row">
                <?php
                $args = array(
                    'post_type' => 'services',
                    'post_per_page' => 6
                );
                $query = new WP_Query($args);
                while ($query -> have_posts() ) {
                    $query -> the_post();
                    //for retriving the meta data we are using the ACF free 
                     plugin for doing it dynamiclly.
                ?>

                <div class="col-lg-4 col-md-6">
                    <!-- Single Service -->
                     <div class="single-service">
                                <i class="<?php the_field('service_icon'); ? 
                                 >"></i>
                                <h4><?php the_title(); ?> </h4>
                                <p><?php the_content(); ?></p>
                      </div>
                </div>

                <?php
                }
                wp_reset_postdata();
                ?>  
  </div>
0 Answers
Related