• Resolved joxyzan

    (@joxyzhan)


    Godday Mario!

    The plugin works excellent for my needs!

    Until I wanted to list all posts where the current user ID is the value of a specific custom field (fetcher) for posts and found that the posts with a category marked with “Exclude from Front Page?” in your plugin settings are excluded in the resulting list (on the users profile page).

    Does that make sense to you when looking at my query below?
    Can you maybe tell me if the query has to be adjusted..? ??

    <?php
    $current_user = wp_get_current_user();
    $user_ID = $current_user->ID;
    
    // The Query to show a specific Custom Field
      
    $the_query = new WP_Query( array( 'meta_key' => 'fetcher', 'meta_value' => $user_ID ) );
    ?>
    <?php
    
    // The Loop [...]
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Marios Alexandrou

    (@marios-alexandrou)

    It’s odd that categories would be excluded on a user’s profile page. Admittedly that’s not a scenario I tested since such profile pages don’t typically have post listings so it very well could be a bug.

    Thread Starter joxyzan

    (@joxyzhan)

    Thank you for answering Mario!

    I would say profile/author pages do typically have post listings, for viewing all posts by a specific author. How does your plugin handle them? I would guess it’s handled through “Exclude from All Archives?”

    I tried to solve my problem using a functions.php snippet for hiding a specific category from the front page:

    function exclude_category_home( $query ) {
    if ( $query->is_front_page ) {
    $query->set( 'cat', '-3' );
    }
    return $query;
    }
    add_filter( 'pre_get_posts', 'exclude_category_home' );

    It works fine for the front page, but it excludes category 3 in my query on the profile page, the same way that your plugin does. Here’s my query in full:

    <?php
    $current_user = wp_get_current_user();
    $user_ID = $current_user->ID;
        
    // Query to show a specific Custom Field
    $the_query = new WP_Query( array( 'meta_key' => 'fetcher', 'meta_value' => $user_ID ) );
      
    // The Loop
    while ( $the_query->have_posts() ) : $the_query->the_post();
    the_title();
    endwhile;
     
    wp_reset_postdata();
    ?>

    I thought that might help you understand if it’s my query or your plugin that needs an adjustment…?

    • This reply was modified 1 year, 6 months ago by joxyzan.
    Plugin Author Marios Alexandrou

    (@marios-alexandrou)

    I misunderstood your initial post. For some reason I thought you were talking about the user’s profile page on the admin side not the publicly visible profile page aka author page.

    So yes, it’s the archive setting that’s interfering with what you’re trying to do since you’re showing an archive. The plugin is design to intercept such queries. There are ways around the plugin, but it’s been a while since I’ve thought about them so what’s needed is not coming to mind.

    Thread Starter joxyzan

    (@joxyzhan)

    Okay!

    The thing is though: even if I deactivate “Exclude from All Archives?” (or even deactivate your plugin) the functions.php-snippet I posted above makes category 3 disappear from my WP_Query. Isn’t that weird?

    With your knowledge maybe you can tell me if my WP_Query has to be adjusted?

    Thread Starter joxyzan

    (@joxyzhan)

    I found the solution!
    Changing the second line of my snippet to:

    if ( $query->is_main_query() && $query->is_front_page() ) {
    
    
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Posts unintentionally excluded in a WP_query’ is closed to new replies.