[Resolved] Author Archives Disappeared (Possibly Linked to GP Upgrade?)

Home Forums Support Author Archives Disappeared (Possibly Linked to GP Upgrade?)

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #906558
    culpable

    Hiya,

    I noticed that on the staging version of my website there are no longer author archives. They are currently showing “Nothing Found”.

    I was given the following code a couple of months ago to get pages (as in, wordpress “pages”) to show in the author archives:

    add_action( 'pre_get_posts', function( $query ) {
        if ( ! $query->is_main_query() || is_admin() ) {
            return;
        }
        if ( $query->is_author ) {
            $query->set( 'post_type', array( 'post', 'page' ) );
            $query->set( 'post__not_in', array(320,25753,25821,25823,25824,25825,25830,25832,25390,25963,26018,26002,25998,25977,26006,26004,25614,25984,25986,25994,25990,26000,25982,25975,26004) );
        }
    } );

    This was working perfectly for a long time, and still is on the live site.

    These are the differences I can see between the two sites:

    Live site (Author archives working):
    GP Premium Version 1.7.8

    Staging site (Author archives not working):
    GP Premium Version 1.8.2

    In addition, two related questions in terms of the efficiency above SQL query:
    1. The majority of the excluded post IDs above are for WP Show Posts. Is it possible to run this query in a more efficient manner (exclude all WP Show Posts? Or maybe “tag” the WP Show Posts somehow to group them)?
    2. The current PHP code above is set to “Run everywhere” on the site. Would it be more efficient to convert it into a shortcode, and then execute that shortcode on only the author archive pages via GP Elements (since these are the only relevant place this query needs to run)?

    Thank you in advance for your assistance.

    #907256
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    1. Do they re-appear if you deactivate that PHP?

    2. What do you mean by WP Show Post? Like those IDs are for WPSP lists themselves? If so, they shouldn’t display by default as they aren’t posts or pages.

    3. I doubt it would make a difference performance-wise.

    Let me know ๐Ÿ™‚

    #907689
    culpable

    Hi Tom,

    1. No, they don’t reappear. I triple checked and it’s running the same code as the live site. This is quite the show stopper :\

    2. My bad โ€“ย I made a mistake. Those are navigational pages which contain post lists from wp show posts (forget I mentioned it)

    3. If you say so ๐Ÿ™‚

    I’m on WordPress 5.1.1 (on both live and staging)

    Please send help :c

    #908256
    Tom
    Lead Developer
    Lead Developer

    Can you try re-saving your permalinks in “Settings > Permalinks”?

    If that doesn’t work, can you try deactivating your plugins one by one to check for conflicts?

    #908280
    culpable

    Neither saving permalinks nor deactivating plugins seemed to fix the issue.

    But… I did make a useful discovery.

    As mentioned there are no posts on the site, only pages. I added a post and that post appeared (by itself) under its author name.

    So it seems like the issue relates to correctly executing the query that relates pages to an author.

    In both the live and staging site, I’m using woody snippets (https://wordpress.org/plugins/insert-php/) to insert the PHP (note they recently had a name change). I’ve tripled checked and in both cases the query is the same (as in OP).

    #908827
    Tom
    Lead Developer
    Lead Developer

    Can you try this?:

    add_action( 'pre_get_posts', function( $query ) {
        if ( ! $query->is_main_query() || is_admin() ) {
            return;
        }
        if ( $query->is_author() ) {
            $query->set( 'post_type', array( 'post', 'page' ) );
            $query->set( 'post__not_in', array(320,25753,25821,25823,25824,25825,25830,25832,25390,25963,26018,26002,25998,25977,26006,26004,25614,25984,25986,25994,25990,26000,25982,25975,26004) );
        }
    } );
    #908842
    culpable

    I implemented it with optimism. Unfortunately, it’s not working (cache cleared)

    #908852
    Tom
    Lead Developer
    Lead Developer

    What if you remove this temporarily?:

    $query->set( 'post__not_in', array(320,25753,25821,25823,25824,25825,25830,25832,25390,25963,26018,26002,25998,25977,26006,26004,25614,25984,25986,25994,25990,26000,25982,25975,26004) );

    #908862
    culpable

    Haha โ€“ย funnily enough that’s the first thing I tried next after confirming that your suggestion wasn’t working. Unfortunately, this didn’t help either.

    But good news Tom โ€“ย I think I found the issue.

    For whatever reason, the version differences in the plugin I’m using to insert PHP โ€“ Woody Ad Snippets (https://wordpress.org/plugins/insert-php/)ย โ€“ย is causing this to fail.

    I downloaded the code snippets plugin you recommended (https://en-ca.wordpress.org/plugins/code-snippets/) and added the same code.

    Both the new and old version of the code you suggested worked, and the pages are displaying. Very strange.

    This is a peculiar error as the other PHP snippets in the plugin are working correctly, AND the same code is working on the live site. I have no idea what could have possibly changed between versions for this odd error to occur. Regardless, this is the nudge I need to move my stuff over into code snippets… that’s what I get for not taking your recommendations seriously ๐Ÿ˜‰

    No, but seriously โ€“ย I apologise for wasting your time. Thank you very much for helping me to navigate this tricky issue.

    One last thing โ€“ which of the above queries (the original one I posted, or the new one you posted) is preferred? (I realize they are quite similar, but still โ€“ is one of the two a ‘best practice’)?

    Thank you for your time Tom ๐Ÿ™‚

    #908873
    Tom
    Lead Developer
    Lead Developer

    Ah – glad you found the issue! Code Snippets is a great plugin.

    If your original code works, it should be fine. I was just trying small tweaks to see if we could find any hints at what was going on ๐Ÿ™‚

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.