• Eva

    (@estoerksonlineno)


    Posts in query only shows when logged inn. I have tried to reset permalink, but still not working. This is my code:

    		<section class="cards">
    					<div class="entry-content card">
    					<?php
    					$query = new WP_Query( 'pagename=yrkesfartoy' );
    
    					// The Loop
    					if ( $query->have_posts() ) {
    						while ( $query->have_posts() ) {
    							$query->the_post();
    							the_post_thumbnail();
    							echo '<h2 class="section-title">' . get_the_title() . '</h2>';
    							echo '<div class="entry-content">';
    							the_excerpt();
    
    							echo '</div>';
    						}
    					}
    
    					/* Restore original Post Data */
    					wp_reset_postdata();
    					?>
    			</div>
    			<div class="entry-content card">
    			<?php
    			$query = new WP_Query( 'pagename=fritidsbat' );
    
    			// The Loop
    			if ( $query->have_posts() ) {
    				while ( $query->have_posts() ) {
    					$query->the_post();
    					the_post_thumbnail();
    					echo '<h2 class="section-title">' . get_the_title() . '</h2>';
    					echo '<div class="entry-content">';
    					the_excerpt();
    					echo '</div>';
    				}
    			}
    
    			/* Restore original Post Data */
    			wp_reset_postdata();
    			?>
    	</div>
    </section><!-- #cards -->

    The page I need help with: [log in to see the link]

Viewing 7 replies - 1 through 7 (of 7 total)
  • Do you want to display a list of posts or a list of pages? If you want to list posts, you’ll need to use name=yrkesfartoy instead of pagename=yrkesfartoy.

    Thread Starter Eva

    (@estoerksonlineno)

    I get the result I want (list of pages), but the problem is that lists are not displayed, only when I am logged inn to WordPress. I have tried to reset the permalinks.

    Are the pages marked as public and do they have a publish date that’s not in the future?

    To check this, edit the page and look at the Status & Visibility section in the editor sidebar. Visibility should be set to Public and Publish should have a date and time that is in the past.

    Thread Starter Eva

    (@estoerksonlineno)

    Yes, they are published.

    Do you have any caching plugins enabled on your site? If so, could you try disabling them and seeing if that fixes the problem?

    Thread Starter Eva

    (@estoerksonlineno)

    No, caching plugins. I have tried to deactivate all plugins, but still not working.

    Moderator bcworkz

    (@bcworkz)

    There’s nothing in your code that would cause this. It works perfectly on my site once I supply valid pagenames. It’s likely your theme or a plugin is interfering with the queries’ proper functioning when logged out.

    To narrow down the cause, please install and activate the health-check plugin. Invoke troubleshooting mode. You should find you code now works correctly. Use the troubleshooting item in the admin bar to restore your theme and plugins one at a time. When your code again fails, the last activated module is the cause.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Query shows posts when logged in, but not when logged out’ is closed to new replies.