Cevaplar
Hiç cevap bulunamadı.
İlk cevabı siz yazın.
$temp_categories = get_categories('hide_empty=0&orderby=name'); $categories = array(); foreach ($temp_categories as $category) $categories[$category->term_id] = $category->cat_name . ' (' . $category->category_count . ')'; echo ' <select id="post_category" name="category" multiple="multiple">'; foreach ($categories as $catid => $catname) echo ' <option id="cat_', $catid, '" value="', $catid, '">', $catname, '</option>'; echo ' </select> <span style="font-size: 3em; text-align: center; display: inline-block; margin-bottom: 8%;">»</span> <select id="category_posts" name="posts[]" multiple="multiple"></select>';
$(document).ready(function() { $(\'#post_category\').change(get_category_posts); }); function get_category_posts() { $(\'#category_posts\').empty(); $("#post_category option:selected").each(function () { var option = $(this); $.getJSON(\'', get_option('siteurl'), '/wp-content/plugins/', WPACP_PLUGIN_DIR_NAME, '/json.php?cat=\' + option.val(), function(posts) { $(\'#category_posts\').append(\'<optgroup label="\' + option.text().replace(/\s*\(\d+\)/gi, \'\') + \'">\'); $.each(posts, function(i, post){ $(\'#category_posts\').append(\'<option value="\' + post.id + \'">\' + post.text + \'</option>\'); }); $(\'#category_posts\').append(\'</optgroup>\'); }); }); };
$cat = !empty($_REQUEST['cat']) ? (int) $_REQUEST['cat'] : 1; $request = $wpdb->get_results(" SELECT ID, post_title FROM {$wpdb->prefix}posts, {$wpdb->prefix}term_relationships, {$wpdb->prefix}term_taxonomy WHERE {$wpdb->prefix}posts.ID = {$wpdb->prefix}term_relationships.object_id AND {$wpdb->prefix}term_relationships.term_taxonomy_id = {$wpdb->prefix}term_taxonomy.term_taxonomy_id AND {$wpdb->prefix}term_taxonomy.taxonomy = 'category' AND {$wpdb->prefix}term_taxonomy.term_id = '{$cat}' AND {$wpdb->prefix}posts.post_type = 'post'"); $posts = array(); foreach ($request as $row) $posts[] = array( 'id' => $row->ID, 'text' => $row->post_title ); echo json_encode ($posts);