Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm trying to echo the content of a single post by using the_content(); but I get an empty result. However when I directly address the global $post, and specifically the post_content property it does show. What can cause such peculiar behaviour?

CODE: the problematic line is near the end

<?php  
get_header(); ?>
<div id="com_page" class="content">
    <ul id="com_list">
        <?php 
        $title = get_the_title();
        $q = new WP_Query(array(
            'post_type'=>'community',
            'numberposts'=>-1,
            'orderby'=>'title',
            'order'=>'asc'));
        if ( $q->have_posts() ) : while ( $q->have_posts() ) : $q->the_post(); ?>
         <li><a href="<?php the_permalink(); ?>" <?php if ($title==get_the_title()) echo "class=com_sel"; ?> ><?php the_title(); ?></a></li>
        <?php endwhile; ?>
             <?php endif; ?>
    </ul>
    <div id="com_content">
         <div id="title">
             <h1>קהילות צעירות<span> <?php wp_reset_query(); the_post(); the_title(); ?><span></h1>
             <?php 
             $title=get_the_title();
             $forum_id =  $wpdb->get_row("SELECT id FROM wp_forum_forums WHERE name='$title'"); // find forum id
             ?>

             </div><!--title-->
         <ul id="com_menu" class=clearfix>
            <li><a href="<?php the_permalink(); ?>" <?php if (!isset($_GET['tab'])) {echo "class=com_sel"; $page = "אודות הקבוצה";} ?>>אודות הקבוצה</a></li>
            <li><a href="<?php the_permalink(); ?>/?tab=events" <?php if (isset($_GET['tab']) && $_GET['tab']=='events') {echo "class=com_sel"; $page = "ארועים";} ?>>ארועים</a></li>
            <li><a href="<?php the_permalink(); ?>/?tab=gallery" <?php if (isset($_GET['tab']) && $_GET['tab']=='gallery') {echo "class=com_sel"; $page = "גלריה";} ?>>גלריה</a></li>
            <li><a href="http://localhost/midor/%D7%A4%D7%95%D7%A8%D7%95%D7%9D/?mingleforumaction=viewforum&f=<?php echo $forum_id->id;  ?>.0">פורום</a></li>
        </ul><!--com_menu-->
        <h1><?php echo $page; ?></h1>
        <?php if (isset($_GET['tab']) && $_GET['tab']=='events'): ?>
        <!-- Events code -->
        <?php elseif (isset($_GET['tab']) && $_GET['tab']=='gallery'):  ?>
        <!-- Gallery code -->
        <?php else: ?>
        <!-- About code -->
         <div id="about_imgs">
             <img src="" alt="">
         </div>
         <div id="about_txt" style="background:red !important;">
           <?php  the_content(); ?>   // not working
           <div class="clear"></div>    
         </div>
        <?php endif; ?> 
    </div><!--com_content-->

</div><!--com_page-->
<?php

get_sidebar();
get_footer(); 
share|improve this question
    
Just to test, could you try running the Page without the <ul> and the custom loop on top? Please tell me if the Error still exists in this case. –  fischi Dec 28 '12 at 9:44
    
And also, are you sure your conditional at the end (with Events, Gallery and About) gets you to the 'About code'? –  fischi Dec 28 '12 at 9:45
    
you are right, it is the cause. When I remove the UL the content does show. Any idea why? –  Matanya Dec 28 '12 at 9:47
    
actually, the UL causing the problem is the #com_menu one, not the #com_list –  Matanya Dec 28 '12 at 9:50
    
Yes, I'm sure it gets me to the about code –  Matanya Dec 28 '12 at 9:51
add comment

1 Answer 1

up vote 1 down vote accepted

After the <ul> part you do reset the query, but you also have to reset the original postdata:

wp_reset_postdata();

and in the line

<li>
<a href="<?php the_permalink(); ?>" <?php if (!isset($_GET['tab'])) {echo "class=com_sel"; $page = "אודות הקבוצה";} ?>>אודות הקבוצה
</a>
</li>

the php and if tags are mixed up, i don't know if PHP understands it like that.

should be like this:

<li>
<a href="<?php the_permalink(); ?>" <?php if (!isset($_GET['tab'])) {echo "class=com_sel"; $page = "אודות הקבוצה";} ?>
        אודות הקבוצה
</a>
</li>

I think this is a mixup with rtl and ltr direction of the language.

share|improve this answer
    
correct! will accept in 2 mins –  Matanya Dec 28 '12 at 9:55
    
cool. just out of curiosity - does PHP understand the Tags when they are written in RTL direction? –  fischi Dec 28 '12 at 9:58
    
the tags themselves are in english, aren't they? –  Matanya Dec 28 '12 at 10:00
    
as for the apparent syntax error it is fine on my end, just wasn't parsed well when I pasted it, due to directionality issues –  Matanya Dec 28 '12 at 10:03
    
yeah they are, but when I look at the code you posted, they are in the opposite direction for me. strange thing, never noticed this before, but sure is correct - when i copy past your version in this window, the direction is written LTR ;) so nevermind :) –  fischi Dec 28 '12 at 10:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.