Advertisement
downloadtaky

functions/postdropdown.php

Mar 22nd, 2011
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.90 KB | None | 0 0
  1. <?php
  2. function display_post_selectbox($class_name='') {
  3.     global $wpdb, $post;
  4.     $table_prefix = $wpdb->prefix;
  5.     $the_output = NULL;
  6.     $last_posts = (array)$wpdb->get_results("
  7.        SELECT {$table_prefix}terms.name, {$table_prefix}terms.term_id
  8.        FROM {$table_prefix}terms, {$table_prefix}term_taxonomy
  9.        WHERE {$table_prefix}terms.term_id = {$table_prefix}term_taxonomy.term_id
  10.                AND {$table_prefix}term_taxonomy.taxonomy = 'category'
  11.        {$hide_check}
  12.    ");
  13.     if (empty($last_posts)) {
  14.         return NULL;
  15.     }
  16.     $used_cats = array();;
  17.     $i = 0;
  18.     foreach ($last_posts as $posts) {
  19.         if (in_array($posts->name, $used_cats)) {
  20.             unset($last_posts[$i]);
  21.         } else {
  22.             $used_cats[] = $posts->name;
  23.         }
  24.         $i++;
  25.     }
  26.     $last_posts = array_values($last_posts);
  27.     $the_output .= '<select name="wordpress_posts" class="'.$class_name.'">';
  28.     foreach ($last_posts as $posts) {
  29.       $the_output .= '<optgroup label="'.apply_filters('list_cats', $posts->name, $posts).'">';
  30.           $where = apply_filters('getarchives_where', "WHERE post_type = 'post' AND post_status = 'publish'" , $r );
  31.           $arcresults = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND ID IN (Select object_id FROM {$table_prefix}term_relationships, {$table_prefix}terms WHERE {$table_prefix}term_relationships.term_taxonomy_id =" . $posts->term_id . ") ORDER BY post_date DESC");
  32.       foreach ( $arcresults as $arcresult ) {
  33.            $the_output .= '<option label="'.apply_filters('the_title', $arcresult->post_title).'" value="'.apply_filters('the_title', $arcresult->post_title).'">'.apply_filters('the_title', $arcresult->post_title) . '</option>';
  34.        }
  35.           $the_output .= '</optgroup>';
  36.        }
  37.        $the_output .= '</select>';
  38.        return $the_output;
  39. };
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement