Recent Posts Element differnt since Update

Hi All,

since the Update, the “Classic Recent Posts” Element is showing not what it was showing before.

based on my previous post: https://theme.co/apex/forum/t/recent-posts-element-showing-incorrect-content/16634 i created a custom post category and choose it, and set the slug only to “einsatzberichte” but it is showing all entries - also this without images (but only category “einsatzberichte” is supposed to have images -> http://feuerwehr-mureck.at/category/einsatzberichte)

what it is showing now:

what it is showing when i choose einsatzberichte wether in “type: berichte or in type: einsatzberichte”:

and what it was showing : https://theme.co/apex/forum/t/recent-posts-element-showing-incorrect-content/16634/3?u=secbit

what is the difference now since the update?

thank you
Patrick

Hi @secBIT,

Thanks for writing in.

I’m not sure if I understand it correctly, selecting a post type will display all posts from that post type, that includes the item without an image. Hence, it’s only normal or are you expecting to display specific posts upon selection of post type?

Then, when adding einsatzberichte in the category, it isn’t really going to work. Because it’s for posts and portfolio category only and it’s not applicable for the custom taxonomy. Unless you have custom code which you use as a shortcode?

This is the line responsible for that

$category = ( $category != '' ) ? $category : ''; $category_type = ( $type == 'post' ) ? 'category_name' : 'portfolio-category';

I compared the new update and the old version and that lines are still the same. It’s for post category and portfolio category only. I’m not sure how it was working on your site when it’s not meant for a custom taxonomy, so I thought it was a custom shortcode.

Thanks!

Hi @Rad
thank you for your response.

So i created based on my other post a custom Post Type “Einsatzberichte” were i entered as well Category “einsatzberichte” and then it only has shown posts with Images -> because it is defined that only “image posts” are stored in category “einsatzberichte”.

After that update, i choose “Type:Einsatzberichte” and “Category:einsatzberichte” and it is not showing anything.

do you get my point?

Thank you
Patrick

Hi Patrick,

You have to override the recent posts shortcode by adding this custom 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' ) );
  $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' || $type == 'einsatz' ) ? 'category_name' : '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 );

  $posts = get_posts( array(
    'orderby'             => 'date',
    'post_type'           => "{$type}",
    'posts_per_page'      => "{$count}",
    'offset'              => "{$offset}",
    "{$category_type}"    => "{$category}",
    'ignore_sticky_posts' => $no_sticky
  ) );

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

    foreach ($posts as $post) {

      if ( $no_image == 'true' ) {
        $image_output       = '';
        $image_output_class = 'no-image';
      } else {
        $image              = wp_get_attachment_image_src( get_post_thumbnail_id( $post->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';
      }

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

    }

  $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' );
}

Let us know how it goes!

Hi thai,

as far as i can see, it has not changed anything.
Any idea?

would it make sense to do the upgrade to “pro” :wink:

Greetings
Patrick

Hi Patrick,

I’ve tried to add the following shortcode to the text element and it’s working fine:

[x_recent_posts type="einsatz" category="Einsatzberichte" count="3"]

It seems like we can’t override the recent posts element in CS.

Can you use the shortcode in the text element instead?

Regards!

Hi thai,

that is working perfect and totally fine for me. thanks for the great Support! :slight_smile:
Patrick

You’re welcome, Patrick. Glad we could help. Just note that overriding the functionality of the shortcodes is not recommended and we do not have support for issues that arise from it and further enhancement. If the custom code will causes an issue in the future, I’d recommend that you use the bundled grid plugins instead.

Thanks.

Thanks for your advise! :slight_smile:

Thanks for understanding.

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