Widgets - Main Sidebar - Latest post links don’t work

Hi @webadmin_auc,

referring to your post:

I have exactly the same problem, here is the answer from the WPML team:
Hi there,

While deactivating cornerstone plugin this issue is not replicated, so seems like a compatibility issue with the plugin, so I have forward the details to our Themes & Plugins Compatibility Team and they will contact the author. Please note that this process may take a while as it depends on how soon the author will reply to our efforts to contact him.

We are closing the ticket but we will keep it for our records. You will be notified the moment we have the author’s cooperation in this process.

Thanks


For me it works perfect, because I don´t use the cornerstone plugin. If you use this plugin I found a workaround but it is not a perfect solution but it works and fix the issue.

Here is my solution:
I found the code line that causes the problem.

This is the following core file: /wp-includes/widgets/class-wp-widget-recent-posts.php

Version 4.8.4 the code is (this works for me):
$r = new WP_Query( apply_filters( ‘widget_posts_args’, array(
‘posts_per_page’ => $number,
‘no_found_rows’ => true,
‘post_status’ => ‘publish’,
‘ignore_sticky_posts’ => true
) ) );

        if ($r->have_posts()) :
        ?>
        <?php echo $args['before_widget']; ?>
        <?php if ( $title ) {
            echo $args['before_title'] . $title . $args['after_title'];
        } ?>
        <ul>
        <?php while ( $r->have_posts() ) : $r->the_post(); ?>
            <li>
                <a href="<?php the_permalink(); ?>"><?php get_the_title() ? the_title() : the_ID(); ?></a>
            <?php if ( $show_date ) : ?>
                <span class="post-date"><?php echo get_the_date(); ?></span>
            <?php endif; ?>
            </li>
        <?php endwhile; ?>
        </ul>
        <?php echo $args['after_widget']; ?>
        <?php
        // Reset the global $the_post as this query will have stomped on it
        wp_reset_postdata();
 
        endif;
    }

Version 4.9.1 the code is:
$r = new WP_Query( apply_filters( ‘widget_posts_args’, array(
‘posts_per_page’ => $number,
‘no_found_rows’ => true,
‘post_status’ => ‘publish’,
‘ignore_sticky_posts’ => true,
), $instance ) );

        if ( ! $r->have_posts() ) {
            return;
        }
        ?>
        <?php echo $args['before_widget']; ?>
        <?php
        if ( $title ) {
            echo $args['before_title'] . $title . $args['after_title'];
        }
        ?>
        <ul>
            <?php foreach ( $r->posts as $recent_post ) : ?>
                <?php
                $post_title = get_the_title( $recent_post->ID );
                $title      = ( ! empty( $post_title ) ) ? $post_title : __( '(no title)' );
                ?>
                <li>
                    <a href="<?php the_permalink( $recent_post->ID ); ?>"><?php echo $title ; ?></a>
                    <?php if ( $show_date ) : ?>
                        <span class="post-date"><?php echo get_the_date( '', $recent_post->ID ); ?></span>
                    <?php endif; ?>
                </li>
            <?php endforeach; ?>
        </ul>
        <?php
        echo $args['after_widget'];

Hope this helps.

Thank you for sharing this solution. :slight_smile:

You are welcome

I received the following message from the wpml team:

------------------------

Hi there,

I just received confirmation from our compatibility team that they have contacted the author and as a workaround, you can go to wp-content/plugins/cornerstone/includes/classes/components/class-wpml.php line no. 19 and comment out the following line:

//add_filter( 'the_permalink', array( $this, 'filter_permalink' ) );
Let me know if the workaround helps.

Thanks

-----------------------------

It works perfect but, do you have an idea how I can outsource the code in the function.php, so that I do not have to edit the core file of the plugin?

Thanks,
Pascal

Hi there,

I tried with functions.php and it’s not working since $this is an existing instance where inaccessible outside that class. You may continue with that temporary solution for now.

Thanks!

Hi Rad,

thanks for your quick replay

You are welcome and thanks for understanding.

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