Mec categories

Hi I am trying to set up a page using a text block and displaying an event category -CalEvents- from MEC.
I am using the following code
[recent_posts count=“2” orientation=“horizontal” category=“CalEvents”] [recent_posts count=“3” orientation=“horizontal” offset=“2” category=“calevents”] [recent_posts count=“3” orientation=“horizontal” offset=“5” category=“calevents”]

However this is not working. Could you tell me what the correct syntax is please?

Thanks

Hi There,

The recent posts shortcode is not working with the custom post types.

You have to override it. Please add this code under functions.php file locates in your child theme:

function x_shortcode_recent_posts_v3( $atts ) {
  extract( shortcode_atts( array(
    'id'           => '',
    'class'        => '',
    'style'        => '',
    'type'         => 'post',
    'count'        => '',
    'category'     => '',
    'offset'       => '',
    'orientation'  => '',
    // 'show_excerpt' => 'true',
    'no_sticky'    => '',
    'no_image'     => '',
    'fade'         => ''
  ), $atts, 'x_recent_posts' ) );

  $allowed_post_types = apply_filters( 'cs_recent_posts_post_types', array( 'post' => 'post', 'mec-events' => 'mec-events' ) );
  $type = ( isset( $allowed_post_types[$type] ) ) ? $allowed_post_types[$type] : 'post';

  $id            = ( $id           != ''     ) ? 'id="' . esc_attr( $id ) . '"' : '';
  $class         = ( $class        != ''     ) ? 'x-recent-posts cf ' . esc_attr( $class ) : 'x-recent-posts cf';
  $style         = ( $style        != ''     ) ? 'style="' . $style . '"' : '';
  $count         = ( $count        != ''     ) ? $count : 3;
  $category      = ( $category     != ''     ) ? $category : '';
  //$category_type = ( $type         == 'post' ) ? 'category_name' : 'portfolio-category';

  if($type == 'post'){
  	$category_type = 'category_name';
  } else if($type == 'mec-events'){
  	$category_type = 'mec_category';
  } else {
  	$category_type = 'portfolio-category';
  }

  $offset        = ( $offset       != ''     ) ? $offset : 0;
  $orientation   = ( $orientation  != ''     ) ? ' ' . $orientation : ' horizontal';
  // $show_excerpt  = ( $show_excerpt == 'true' );
  $no_sticky     = ( $no_sticky    == 'true' );
  $no_image      = ( $no_image     == 'true' ) ? $no_image : '';
  $fade          = ( $fade         == 'true' ) ? $fade : 'false';

  $js_params = array(
    'fade' => ( $fade == 'true' )
  );

  $data = cs_generate_data_attributes( 'recent_posts', $js_params );

  global $post;

  $output = "<div {$id} class=\"{$class}{$orientation}\" {$style} {$data} data-fade=\"{$fade}\" >";

    $q = new WP_Query( array(
		'orderby'             => 'date',
		'post_type'           => "{$type}",
		'posts_per_page'      => "{$count}",
		'offset'              => "{$offset}",
		"{$category_type}"    => "{$category}",
		'ignore_sticky_posts' => $no_sticky,
		'post__not_in'        => array($post->ID)
    ) );

    if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post();

      if ( $no_image == 'true' ) {
        $image_output       = '';
        $image_output_class = 'no-image';
      } else {
        $image              = wp_get_attachment_image_src( get_post_thumbnail_id(), 'entry-cropped' );
        $bg_image           = ( $image[0] != '' ) ? ' style="background-image: url(' . $image[0] . ');"' : '';
        $image_output       = '<div class="x-recent-posts-img"' . $bg_image . '></div>';
        $image_output_class = 'with-image';
      }

      // $excerpt = ( $show_excerpt ) ? '<div class="x-recent-posts-excerpt"><p>' . preg_replace('/<a.*?more-link.*?<\/a>/', '', cs_get_raw_excerpt() ) . '</p></div>' : '';

      $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( csi18n('shortcodes.recent-posts-permalink'), the_title_attribute( 'echo=0' ) ) ) . '">'
                 . '<article id="post-' . get_the_ID() . '" class="' . implode( ' ', get_post_class() ) . '">'
                   . '<div class="entry-wrap">'
                     . $image_output
                     . '<div class="x-recent-posts-content">'
                       . '<h3 class="h-recent-posts">' . get_the_title() . '</h3>'
                       . '<span class="x-recent-posts-date">' . get_the_date() . '</span>'
                       // . $excerpt
                     . '</div>'
                   . '</div>'
                 . '</article>'
               . '</a>';

    endwhile; endif; wp_reset_postdata();

  $output .= '</div>';

  return $output;
}

add_action('wp_head', 'change_recent_posts_to_v3');
function change_recent_posts_to_v3() {
  remove_shortcode( 'x_recent_posts' );
  add_shortcode( 'x_recent_posts', 'x_shortcode_recent_posts_v3' );
}

After that using these shortcodes:

[x_recent_posts count="2" type="mec-events" orientation="horizontal" category="CalEvents"] [x_recent_posts count="3" type="mec-events" orientation="horizontal" offset="2" category="CalEvents"] [x_recent_posts count="3" type="mec-events" orientation="horizontal" offset="5" category="CalEvents"]

Hope it helps :slight_smile:

Hi
Thank you once again for your support.
Yes that has worked, although when in Pro Editor, the images are not being displayed, although when the site is viewed they are visible.

Also on the MEC editor, in the Wordpress Dashboard, when looking at the list of events, is it possible to add “Categories” to the columns being displayed? It is not showing as an option in the Screen Options.

Many thanks

Hi there,

That will be a hard thing to do as the MEC images are not normal Feature Images and are part of the Custom Post Type. I suggest that you consider taking another route and that is the MEC own Shortcode system.

Go to ME Calendar > Shortcodes and click on Add new. There you will find many options and possible views to add what you want and select the category in question.

Then simply copy the shortcode and paste it into the Classic Raw Content element in the Cornerstone.

That should do the trick for you.

Kindly open up new threads for additional questions as it will help us to focus on each issue and give you a better support which you deserve. Having a long threads makes the maintaining job harder and also it will be harder for the other customers to find the correct information if they have similar issues. You are always welcomed to reply to this thread to follow up the same question.

Thank you.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.