WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [closed] Really wired problem! please look at this. (11 posts)

  1. prionkor
    Member
    Posted 3 years ago #

    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

    query_posts('post_type=event&order_by=start_date&order=DESC&meta_key=start_time&meta_compare=>&meta_value='.time());
    	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);
    		}else{
    			$end_time = "N/A";
    		}
    		if(get_post_meta($post->ID, 'start_time', true)){
    			$start_time = get_post_meta($post->ID, 'start_time', true);
    		}else{
    			$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>
        <?php
    	endwhile; endif;

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

  2. prionkor
    Member
    Posted 3 years ago #

    Hi, no help!?? I wraped the code into a function:

    function latestEvents(){
     all codes;
    }

    and call the function in sidebar.

    latestEvents();

    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!

  3. prionkor
    Member
    Posted 3 years ago #

    should i place the thread in advanced forum?

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

  5. kapilj
    Member
    Posted 3 years ago #

    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. http://codex.wordpress.org/Template_Tags/get_posts

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

    Hope this works!
    Kapil

  6. prionkor
    Member
    Posted 3 years ago #

    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?

  7. kapilj
    Member
    Posted 3 years ago #

    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!
    Kapil

  8. prionkor
    Member
    Posted 3 years ago #

    Thanks for your help kapil! greatly appreciated!

  9. imah
    Member
    Posted 3 years ago #

    Hello,

    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 141.2.24.106

    Please help me as soon as possible!

  10. kapilj
    Member
    Posted 3 years ago #

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

    Thanks!
    Kapil

  11. prionkor
    Member
    Posted 3 years ago #

    @imah: Please open a new thread.

Topic Closed

This topic has been closed to new replies.

About this Topic