0

I have created shortcode snippet to generate the list of custom post type. But I am not able to filter based on taxonomy.

Below is my code:

add_action( 'init', 'wpse36453_register_shortcode' );
/**
 * Registers the shortcode with add_shortcode so WP knows about it.
 */
function wpse36453_register_shortcode()
{
    add_shortcode( 'package_list', 'package_list_shortcode' );
}

/**
 * The call back function for the shortcode. Returns our list of posts.
 */
function package_list_shortcode( $args )
{
    // get the posts
   // define attributes and their defaults
    extract( shortcode_atts( array (
      'post_type'=> 'br_packages',
      'br_packages_activities' => '',
      //'orderby' => 'date',
      //'order' => 'DESC',
      'category' => '',
   ), $atts ) );
   $options = array(
        'post_type'=> 'br_packages',
        'br_packages_activities'=> $atts,
    );
   $the_query = new WP_Query( $options );
    // No posts? run away!
    $out .='<div class="vcex-module vcex-recent-news clr wpex-row gap-10 vc_custom_1525090633924 row">';
    if ( $the_query->have_posts() ) :

    /**
     * Loop through each post, getting what we need and appending it to 
     * the variable we'll send out
     */ 
    while ( $the_query->have_posts() ) : $the_query->the_post();

        $out.='<div class="col col-md-4 span_1_of_3 vcex-recent-news-entry-wrap">';
        $out.='<article class="vcex-recent-news-entry clr no-left-padding post-8325 post type-post status-publish format-standard has-post-thumbnail hentry category-news-2 entry has-media">';
        $out.='<div class="vcex-news-entry-details clr">';
        $out.='<div class="vcex-news-entry-thumbnail clr">';
        if ( ICL_LANGUAGE_CODE=='fr' ) {
        $out.='<a href="'.get_permalink().'" title="'.get_the_title( ).'">
                    <img class="home-image-center" src="'.get_the_post_thumbnail_url().'" alt="Respect Campaign Monument" data-no-retina="" width="350" height="269">
                </a>
            </div>
            <header class="vcex-recent-news-entry-title entry-title">
                <h2 class="vcex-recent-news-entry-title-heading" style="font-size:16px;color:#ffffff;">
                    <a href="'.get_permalink() .'">'.get_the_title().'</a>
                </h2>
            </header>
            <div class="vcex-recent-news-entry-excerpt clr">
                <div class="entry">
                    ' . wp_trim_words(get_the_excerpt(), 28, '....') . '
                </div>
                <div class="button-center"><a href="'.get_permalink() .'" class="theme-button ">EN SAVOIR PLUS</a></div>
            </div>
        </div>
    </article>
</div>
        ';
  } else {
$out.='<a href="'.get_permalink().'" title="'.get_the_title( ).'">
                    <img class="static-home-image" src="/wp-content/themes/total-child-theme/images/latest-news-2.png" />
                    <img class="home-image-center" src="'.get_the_post_thumbnail_url().'" alt="Respect Campaign Monument" data-no-retina="" width="350" height="269">
                </a>
            </div>
            <header class="vcex-recent-news-entry-title entry-title">
                <h2 class="vcex-recent-news-entry-title-heading" style="font-size:16px;color:#ffffff;">
                    <a href="'.get_permalink() .'">'.get_the_title().'</a>
                </h2>
            </header>
            <div class="vcex-recent-news-entry-excerpt clr">
                <div class="entry">
                    ' . wp_trim_words(get_the_excerpt(), 28, '....') . '
                </div>
                <div class="button-center"><a href="'.get_permalink() .'" class="theme-button ">READ MORE</a></div>
            </div>
        </div>
    </article>
</div>
        ';

  }
    endwhile;
    wp_reset_postdata();
    endif;
    $out .= '</div>';
    return $out;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.