Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1018620
    asewellDSA
    Participant

    After updating the X plugin, the recent_posts shortcode with count=”1″ will not save in Visual / Frontend editor. When entered in text mode and Updating it saves. However, if you simply go to the Frontend editor or the Visual Composer and simply click Update without editing anything, it will delete the count = 1 part of the shortcode. Post type is set to Posts. As a note, if count = 2 and up, everything works as it should. It’s only when count = 1.

    Also, when selecting Post Count = 1 using the dropdown list and clicking save in the pop-up window, and then opening the window again, Post Count returns to – Select Option – in the dropdown.

    Thanks in advance!

    If you need any other information, please let me know.

    #1018698
    Jade
    Moderator

    Hi there,

    Would you mind providing us with login credentials so we can take a closer look? To do this, you can make a post with the following info:

    – Link to your site
    – WordPress Admin username / password
    – FTP credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    #1020097
    asewellDSA
    Participant
    This reply has been marked as private.
    #1020352
    Nabeel A
    Moderator

    Hi again,

    To fix the issue, Please add this code to your child theme’s functions.php:

    function x_shortcode_recent_posts_count_one( $atts ) {
      extract( shortcode_atts( array(
        'id'          => '',
        'class'       => '',
        'style'       => '',
        'type'        => 'post',
        'count'       => '',
        'category'    => '',
        'offset'      => '',
        'orientation' => '',
        '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'      ) ? 'category_name' : 'portfolio-category';
      $offset        = ( $offset      != ''          ) ? $offset : 0;
      $orientation   = ( $orientation != ''          ) ? ' ' . $orientation : ' horizontal';
      $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 );
    
      $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
        ) );
    
        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';
          }
    
          $output .= '<a class="x-recent-post' . $count . ' ' . $image_output_class . '" href="' . get_permalink( get_the_ID() ) . '" title="' . esc_attr( sprintf( __( 'Permalink to: "%s"', csl18n() ), 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>'
                         . '</div>'
                       . '</div>'
                     . '</article>'
                   . '</a>';
    
        endwhile; endif; wp_reset_postdata();
    
      $output .= '</div>';
    
      return $output;
    }
    
    add_action('init', 'set_default_value_to_one', 9999999 );
    
    function set_default_value_to_one () {
    
    remove_shortcode( 'recent_posts' );
    add_shortcode( 'recent_posts', 'x_shortcode_recent_posts_count_one' );
    
    }

    Let us know how this goes!

    #1020860
    asewellDSA
    Participant
    This reply has been marked as private.
    #1021495
    Rad
    Moderator

    Hi there,

    It’s due to Visual Composer’s behavior. When the default value is set it will then remove it, a default value is treated as “nothing changed” since user let the default value. Then VC remove it.

    It’s the same as empty value as default since it’s default then it will be removed. But this time, 1 is the default value.

    But, we can add some workaround if count is empty, but this is only applicable to rendering and not directly to the Visual Composer’s options.

    Change this code

    $count = ( $count != '' ) ? $count : 3;

    to this,

    $count = ( $count != '' ) ? $count : 1;

    Cheers!

    #1022109
    asewellDSA
    Participant

    That worked! Thank all of you for all of your help. I really appreciate it!

    #1022380
    Rupok
    Member

    You are welcome!

    Glad that it helped. Feel free to let us know if you face any other issue. We’ll be happy to assist you.

    Thanks for using X.

    Cheers!

  • <script> jQuery(function($){ $("#no-reply-1018620 .bbp-template-notice, .bbp-no-topic .bbp-template-notice").removeClass('bbp-template-notice'); }); </script>