Tag repetition, article display error after X update

Hi there, I´m looking to update X on a site that has some amount of customization.
The basic layout on the staging server is preserved. There were font awesome social icons issues that are sorted after looking at similar cases on this forum.
Not sorted:

  • Article display broken on internal pages
  • repetition of wordpress tags (keywords)
    Details below:

Hi There @Mbzo

Thanks for writing in! I have tried to login to your WordPress backend, but it seems that your login credentials are invalid.

ERROR: The username or password you entered is incorrect.

We don’t have any known issues when adding special characters as I have tested here.

Thanks!

Sorry about that. Here goes:

Hi There,

Upon checking your website, I could see that you have 42 active plugins.

Please follow up the steps below:

  1. Test for a plugin conflict. You can do this by deactivating all third-party plugins, and see if the problem remains. If it’s fixed, you’ll know a plugin caused the problem, and you can narrow down which one by reactivating them one at a time.
  2. Switch to parent theme to check the issues persist or NOT.

Let us know how it goes!

Ok, deactivating other plugins (except Cornerstone and Revolution Slider) removes the tag and display errors. Now here is a call to undefined function csl18n() on internal pages. Narrowed this error down to a snippet to show related posts by tag (functions.php) here:

function x_recent_posts_related( $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}\" >";
  	/* Related Posts by Tags */
  	global $post;
	$tags    = wp_get_post_tags($post->ID);
	$tag_ids = array();
  	if(!empty( $tags )){
	    foreach($tags as $individual_tag){
	    	$tag_ids[] = $individual_tag->term_id;
	    }
	}
	/* End / Related Posts by Tags */
	$q = new WP_Query( array(
		'tag__in'             => $tag_ids,
		'post__not_in'        => array($post->ID),
		'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', 'x_child_init' );
function x_child_init(){
	add_shortcode( 'x_recent_posts_related', 'x_recent_posts_related' );
}

csl18n() - What should I change here to make it work again?

Hi,

It needs to be updated to work with the latest version of theme.

Kindly change that code with this


function x_recent_posts_related( $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' ) ? '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(
    'tag__in'             => $tag_ids,
    'post__not_in'        => array($post->ID),
    '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}\" >";
/* Related Posts by Tags */
      global $post;
    $tags    = wp_get_post_tags($post->ID);
    $tag_ids = array();
      if(!empty( $tags )){
        foreach($tags as $individual_tag){
            $tag_ids[] = $individual_tag->term_id;
        }
    }
    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( 'init', 'x_child_init' );
function x_child_init(){
    add_shortcode( 'x_recent_posts_related', 'x_recent_posts_related' );
}

Hope that helps

Yes, that helps alot. Many thanks!

You are most welcome. :slight_smile:

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