Согласен.Но работает ни так ни эдак.
On Thursday, July 26, 2012 4:16:39 PM UTC-5, yantar wrote:вроде параметр называется не post_type, а просто type? http://codex.wordpress.org/Function_Reference/get_categories
--
С уважением,
Яна Таран
2012/7/26 Cyrill KALITA <cyrill...@gmail.com>У меня есть custom post type, ioni_codexЯ пользуюсь встроенными категориями Wordpress для группировки коихЯ хочу вывести все категории, используемые моим ioni_codex.$myargs = array ('post_type' => 'ioni_codex');$categories = get_categories( $myargs );Однако вместо этого мне выводится весь список всех категорий, в которых есть хоть один пост - не обращая внимания на указанный тип поста.Что я делаю не так?--
http://groups.google.com/group/ru-wordpress
ну, судя по коду и не должно работать, как ни обидно :(get_categories внутри себя http://core.trac.wordpress.org/browser/tags/3.4.1/wp-includes/category.php#L0 вызывает get_terms http://codex.wordpress.org/Function_Reference/get_terms а у этой функции я не вижу ограничения по посттайпуможет, стоит воспользоваться отдельной таксономией для нужного посттайпа? ну или свою функцию писать
--
С уважением,
Яна Таран
2012/7/26 Cyrill KALITСогласен.
Но работает ни так ни эдак.
On Thursday, July 26, 2012 4:16:39 PM UTC-5, yantar wrote:
вроде параметр называется не post_type, а просто type? http://codex.wordpress.org/Function_Reference/get_categories
--
С уважением,
Яна Таран
2012/7/26 Cyrill KALITAУ меня есть custom post type, ioni_codex
Я пользуюсь встроенными категориями Wordpress для группировки коихЯ хочу вывести все категории, используемые моим ioni_codex.$myargs = array ('post_type' => 'ioni_codex');$categories = get_categories( $myargs );Однако вместо этого мне выводится весь список всех категорий, в которых есть хоть один пост - не обращая внимания на указанный тип поста.Что я делаю не так?--
http://groups.google.com/group/ru-wordpress
А вот и переписаная функция--/* get terms limited to post type
@ $taxonomies - (string|array) (required) The taxonomies to retrieve terms from.
@ $args - (string|array) all Possible Arguments of get_terms http://codex.wordpress.org/Function_Reference/get_terms
@ $post_type - (string|array) of post types to limit the terms to
@ $fields - (string) What to return (default all) accepts ID,name,all,get_terms.
if you want to use get_terms arguments then $fields must be set to 'get_terms'
*/
function get_terms_by_post_type($taxonomies,$args,$post_type,$fields = 'all'){
$args = array(
'post_type' => (array)$post_type,
'posts_per_page' => -1
);
$the_query = new WP_Query( $args );
$terms = array();
while ($the_query->have_posts()){
$the_query->the_post();
$curent_terms = wp_get_object_terms( $post->ID, $taxonomy);
foreach ($curent_terms as $t){
//avoid duplicates
if (!in_array($t,$terms)){
$terms[] = $c;
}
}
}
wp_reset_query();
//return array of term objects
if ($fields == "all")
return $terms;
//return array of term ID's
if ($fields == "ID"){
foreach ($terms as $t){
$re[] = $t->term_id;
}
return $re;
}
//return array of term names
if ($fields == "name"){
foreach ($terms as $t){
$re[] = $t->name;
}
return $re;
}
// get terms with get_terms arguments
if ($fields == "get_terms"){
$terms2 = get_terms( $taxonomies, $args );
foreach ($terms as $t){
if (in_array($t,$terms2)){
$re[] = $t;
}
}
return $re;
}
}
Оригинал - взят отсюда:
http://groups.google.com/group/ru-wordpress
/* get terms limited to post type@ $taxonomies - (string|array) (required) The taxonomies to retrieve terms from.@ $args - (string|array) all Possible Arguments of get_terms http://codex.wordpress.org/Function_Reference/get_terms@ $post_type - (string|array) of post types to limit the terms to@ $fields - (string) What to return (default all) accepts ID,name,all,get_terms.if you want to use get_terms arguments then $fields must be set to 'get_terms'*/
function get_terms_by_post_type($taxonomies,$args,$post_type,$fields = 'all'){$args = array('post_type' => (array)$post_type,'posts_per_page' => -1);$the_query = new WP_Query( $args );$terms = array();while ($the_query->have_posts()){$the_query->the_post();$curent_terms = wp_get_object_terms( $post->ID, $taxonomy);foreach ($curent_terms as $t){//avoid duplicatesif (!in_array($t,$terms)){
$terms[] = $t;
Nope.
Functions.php
Столкнулась с такой же проблемой.расскажите поподробнее куда вставлять вами написанную функцию и что еще надо дописать чтобы работало. Спасибо