pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

3th private pastebin - collaborative debugging tool What's a private pastebin?


Posted by michael on Sat 7 Mar 13:33
report abuse | download | new post

  1. <?php
  2.  
  3.         /*      Preconditions:
  4.  
  5.                 1. You need to display articles from just one category. (You need the category's ID!)
  6.                 2. You have a custom field which includes a date written in the yyyy-mm-dd-format.
  7.                 3. You need to sort your articles by the value of this very custom field in ascending order.
  8.                 4. You do not want to show articles that are in the past - depending on the value of the custom field.
  9.                 5. You want to show only published articles.
  10.  
  11.                 Things you have to fill in are marked with [[ and ]]
  12.  
  13.         */
  14.  
  15.         $querystr = "
  16.                 SELECT * FROM $wpdb->posts
  17.                 LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
  18.                 LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
  19.                 LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
  20.                 WHERE $wpdb->term_taxonomy.term_id = [[ Category-ID ]]
  21.                 AND $wpdb->term_taxonomy.taxonomy = 'category'
  22.                 AND $wpdb->posts.post_status = 'publish'
  23.                 AND $wpdb->postmeta.meta_key = '[[ Name of Custom Field ]]'
  24.                 AND STR_TO_DATE($wpdb->postmeta.meta_value, '%Y-%m-%d') >= NOW()
  25.                 ORDER BY $wpdb->postmeta.meta_value ASC
  26.         ";
  27.                
  28.         $posts = $wpdb->get_results($querystr);
  29.         foreach ($posts as $post) :
  30.                 setup_postdata($post);
  31.                
  32. ?>
  33.  
  34.         <!-- Whatever shall be displayed -->
  35.  
  36. <?php endforeach; ?>

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me so that I can delete my post