• Resolved samcrawshaw

    (@samcrawshaw)


    Yo mo fo’s,

    I’ve done a duplicate post over in the Plugins section.

    I’ve flummoxed myself with an if statement. Here is my code:

    if (is_page(64)){
    	$recent = new WP_Query("page_id=64");	//Define the post
    	while($recent->have_posts()) : $recent->the_post();	//Start the loop
    		the_content();	//Get the content
    		endwhile;}	//End loop

    When I run the statement I get the 404 page. It pulls in the post out of the if statement.

    I am using wp_nav_menu() to call in the navigation. Should this matter?

    It did work at one point but I’m struggling to fathom what I did wrong. I am also using the wp_reset_query in the footer.

    The url reads /contact but is pulling in the 404 page.
    N.B. 64 is id of my contact page (not post).

    Thanx for looking,
    Sam

    TITLE EDIT: Couldn’t spell.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    Your code would not result in a 404. If the page ID were invalid, the new WP_Query would return an empty query object and the while loop would not run, nothing more.

    Check your nav menu definitions, something is wrong there that is causing the 404. You say the URL reads /contact, this apparently is not a valid slug. What is the slug when you edit the page?

    Thread Starter samcrawshaw

    (@samcrawshaw)

    Hi bcworkz,

    I meant the url reads //localhost/mysite/contact but it’s not pulling in the page.

    The source code looks like this when outputted:

    <li id="menu-item-127" class="menu-item menu-item-type-taxonomy menu-item-object-category menu-item-127"><a href="https://localhost/mysite/projects/">Projects</a></li>
    <li id="menu-item-130" class="menu-item menu-item-type-post_type menu-item-object-page menu-item-130"><a href="https://localhost/mysite/contact/">Contact</a></li>
    
    EDIT: Well shiver mi timbers, once I reactivated the plugins it started working again!?
    
    Thanks for your help bcworkz.
    
    Regards,
    Sam

    The back end also throws out a 404 when I click on View Page permalink.

    I’ve tried deactivating all my plugins but still no joy.

    EDIT: Well, shiver-mi-timbers. Once i reactivated the plugins it started working again.

    Thanx for your help bcworkz.

    Regards,
    Sam

    Thread Starter samcrawshaw

    (@samcrawshaw)

    Resolved

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘basic if statement’ is closed to new replies.