• Resolved chris12357

    (@chris12357)


    Thank you Enguerran for creating this plugin. I have been using it for about a year now I think but I noticed yesterday the Insert Related Article Button stopped working.

    When I click the button the popup no longer shows a list of articles to insert into the page and the filter doesn’t work because the list is empty.

    I hadn’t done any changes to my site recently so I don’t think it was an update that caused the issue. I upgraded to 4.7.3 to see if it would fix the problem and did a repair on my db but the update didn’t fix the problem and the database was fine.

    I’m not really sure how to debug this. I changed show_posts in related-post-shortcode/related-post-shortcode.php from -1 to 450 and the plugin will then populate the list but not with all the posts. I also added the post_status to just show published posts mostly because I wanted to see if it would remove drafts from the list.

    function related_post_shortcode_getPostsIds() {
       $posts = query_posts(array(
    			'show_posts'=> 450,
                            'post_status' => array( 'publish'),
    		));

    I assume this means query_posts is failing to return the the list of all my posts but as I am not a wordpress developer I’m not really sure how to further debug this.

    Anyone having a problem with this?

    • This topic was modified 7 years, 8 months ago by chris12357.
    • This topic was modified 7 years, 8 months ago by chris12357.
Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Author enguerranws

    (@enguerranws)

    Hi,

    I’ll take a look into this. Thank you for reporting the issue!

    Best regards,
    Enguerran

    Thread Starter chris12357

    (@chris12357)

    Thanks. Let me know if you need any more info. The plug in is still working on my other sites, it just stopped on the one I use the most ??

    Plugin Author enguerranws

    (@enguerranws)

    I checked the issue on a fresh install and on a blog with thousands of posts and nearly 30 plugins installed. It’s working fine on both cases.

    To debug this, you could put anywhere in your theme this part of code, just in order to see if you get something from query_posts().

    
    $posts_check = query_posts(array(
    			'show_posts'=> -1,
    		));
     var_dump($posts_check);
    

    If it doesn’t work as expected, you should check your posts and post types: query_posts() as a post_type parameter which is set to “post” by default.

    It means that currently, the plugin queries only posts (not pages) from post type “post” to populate its suggestions.

    Plugin Author enguerranws

    (@enguerranws)

    Hi,

    Just to check if you still have this issue, let me know.

    Best regards,
    Enguerran

    Thread Starter chris12357

    (@chris12357)

    Sorry I missed your earlier reply. I am still having a problem. I did some poking at the plugin code and had found that by changing showposts from -1 to one less than the number of posts I have makes the problem go away.

    I only have this problem with of my sites though. I’ll try your recommendation today

    Thanks

    Plugin Author enguerranws

    (@enguerranws)

    I’m digging into query_posts docs. What I can say :
    – it’s not show_posts parameter: in the plugin, it’s showposts, so I guess it’s just a typo on this topic, but can you check for this?
    showposts is a deprecated parameter. I should have used posts_per_page. I’ll update the plugin accordingly.

    Best regards,
    Enguerran

    Plugin Author enguerranws

    (@enguerranws)

    Updated to 1.1, I changed showposts parameter to posts_per_page. Can you update and tell me if it fixes your issue?

    Thread Starter chris12357

    (@chris12357)

    The show_posts confusion was from my original comment. It is showpost. I tried changing it to posts_per_page last week and it didn’t make a difference.

    Somewhat off topic, I was also looking into using get_posts() as opposed to query_posts() with numberposts as an argument. The documentation says query_posts alters the main loop but I don’t really understand the context differences between get_posts and query_posts. At some point I thought I’d look at the code that the insert link button as the popup as a similar functionality.

    Thank you for your support. I’ll post again after I try a few more things.

    Thread Starter chris12357

    (@chris12357)

    You are really quick! :-). Yes. I’ll try it.

    Plugin Author enguerranws

    (@enguerranws)

    I think you are right, I think query_posts is messing somewhere. However, it would be cleaner to use get_posts() instead. I’ll do that quickly.

    Plugin Author enguerranws

    (@enguerranws)

    Update to 1.2, which is using get_posts with posts_per_page. It shouldn’t break anymore.

    By the way, thank you for helping me see and resolve this issue.

    Best regards,
    Enguerran

    Thread Starter chris12357

    (@chris12357)

    I tried the 1.1 update which did not solve the problem. I suspect that the problem is my database, but I don’t no why yet. No one else has reported a problem either but at least my issue is documented here in case someone else comes looking.

    I’ll try to debug this further today.

    I see you just published 1.2 so I’ll give that a try right now too.

    Plugin Author enguerranws

    (@enguerranws)

    Just to be sure: can you tell me if there’s any errors in your JS console (and paste it there if so)?

    Thread Starter chris12357

    (@chris12357)

    Thank you for your help with Related Post Shortcode. After a somewhat painful debugging session it seems that my problem was not in the plugin itself. Looks like I was running out of memory in wp-db.php when the plugin called query_posts() or get_posts(). I increased WP_MEMORY_LIMIT from96M to 256M and that fixed the problem. I consider the matter resolved but if there is any other information you’d like I’ll provide it.

    While perhaps moot at this point, there were some errors is the javascript console. I didn’t copy them and I can go back and change my config to get them if you still want to see them but the error was because$filtered was null in related-post-shortcode.php when I ran out of memory so posts was null when the JS code in rps-popin.html runs and posts.length was invalid.

           function updatePostsList (posts){
              var options = "";
              for (var i = 0; i < posts.length; i++) {
                options += '<li data-value="'+posts[i].value+'">'+posts[i].text+'</li>';
              }
              $("#rps-list", context).html(options).find('li').on('click', function () ...
    • This reply was modified 7 years, 8 months ago by chris12357.
Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Insert Related Article Button Stopped Working’ is closed to new replies.