Support » Developing with WordPress » Really wired problem! please look at this.

  • Resolved Sisir


    Hi, its me again :). I am making an event listing system where i have a event post type with meta fields. In sidebar i am listing upcoming events.

    When i place the code for upcoming events in sidebar it works. But i dont wanna put the codes in sidebar rather i want to put them in function.php as i have a plan to make a plugin/widget later for flexibility.

    So, i have put all the codes in a function in function.php file and call it in sidebar. but php can’t find the meta values!! it does find the title, permalinks but meta values are unset! it’s looks too wired to me. Here is the code, let me know if i am doing something wrong or its a but. i am using wordpress 3.0.1

    	if(have_posts()) : while(have_posts()) : the_post();
    		if(get_post_meta($post->ID, 'end_time', true)){
    			$end_time = get_post_meta($post->ID, 'end_time', true);
    			$end_time = "N/A";
    		if(get_post_meta($post->ID, 'start_time', true)){
    			$start_time = get_post_meta($post->ID, 'start_time', true);
    			$start_time = "N/A";
        <h1><a href="<?php the_permalink(); ?>" title="<?php the_title();?>"><?php the_title();?></a></h1>
        <small><?php echo time_diff($start_time, $end_time); ?></small>
    	endwhile; endif;

    update: it seems to find the meta values in query_posts. but not below it!

Viewing 10 replies - 1 through 10 (of 10 total)
  • Hi, no help!?? I wraped the code into a function:

    function latestEvents(){
     all codes;

    and call the function in sidebar.


    the forum in so busy it i think my thread is not showing for one hour. The mods might want to increase the number of threads showing in front page!

    should i place the thread in advanced forum?

    Moderator Ipstenu (Mika Epstein)


    Lead Plugin Wrangler

    Moved to advanced. Not a clue at the moment and not enough time to sort it out today.

    There is 2 ways to sort out this issuse:

    1. Use “get_posts” function instead of “query_posts” (recommended one), there may be chances that $post conflict with the global $post variable.

    2. Define ‘global $post;’ in start of the function

    Hope this works!

    Hi, thanks. The problem was i did not define the global $post. It worked with query_posts. What is the basic different between get_posts and query_posts? Both are used to run mysql query right?

    The basic difference is between get_posts and query_posts is:

    When we use query_posts, it redefined all the global variables and

    When when we use get_posts it runs as a normal MySql query and return the result set.


    Thanks for your help kapil! greatly appreciated!


    Why I can’t log in into my blog. The computer show:

    Your connection to this server has been blocked in the firewall.
    You need to contact your hosting provider for further information.
    Your blocked IP address is

    Please help me as soon as possible!

    Please share the link of your blog, I will try to help you.


    @imah: Please open a new thread.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Really wired problem! please look at this.’ is closed to new replies.