Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Taxonomy Images Parameters WordPress

  • SOLVED

I am currently using the Taxonomy Images plugin and all is well except for the fact that I'm trying to get it to display the children of a parent term.

As far as i can see the Taxonomy Images plugin doesn't allow this parameter to be parsed.

Any ideas on how to get it to filter the terms by the 'parent' parameter aswell?

Here is the code i'm using.

<?php
$terms = apply_filters( 'taxonomy-images-get-terms', '', array(

'taxonomy' => 'mycustomtaxonomy',
'parent' => $termID

) );

if ( ! empty( $terms ) ) {


foreach( (array) $terms as $term ) {


$termlink=esc_url( get_term_link( $term, $term->taxonomy ) );



echo '<a href="' . $termlink . '">' . wp_get_attachment_image( $term->image_id, 'gallery-thumb' ) . '</a>';

//echo $term->description;


}


}
?>

Answers (2)

2012-07-24

Michael Caputo answers:

Have you tried specifying an ID for the PARENT? instead of using a variable? just to test it?

Also, you shouldn't end your array with a comma (after $termID)


floy comments:

Hey Michael,
Yeah I have tried specifiying an ID instead of the variable too, still nothing. Just displays all the terms from the taxonomy.

My fault with the comma!


Michael Caputo comments:

Does this help?

<blockquote>
parent
(integer) Get direct children of this term (only terms whose explicit parent is this value). If 0 is passed, only top-level terms are returned. Default is an empty string.
</blockquote>

I'm not sure you can specify a taxonomy ID, it might be either true or false, or 1 or 0.


Michael Caputo comments:

or this:

<blockquote>child_of
(integer) Get all descendents of this term. Default is 0.
</blockquote>


floy comments:

Hey Michael,
I have used the 'parent' paremeter before whilst listing child terms without the use of the taxonomy images plugin. See the code below.

Where 'parent' is the ID of the term (from the taxonomy) you wish to display the children of. This code is fully functional and works.

<?php

$args = array('hide_empty' => 0, 'orderby' => 'term_group', 'parent' => '7');

$terms = get_terms('gallerycat', $args);

if($terms) :

$output .= '<ul>';

$output .= '<li><a class="top" href="#open">'.__('Job Category', 'appthemes').'</a> <ul>';

foreach($terms as $term) :

if($parent = $term->parent) :

$class = 'child';

else :

$class = 'parent';

endif;

$output .= '<li class="'.$class.'"><a href="'.$term->slug.'">'.$term->name.'</a></li>';

$parent = $term->parent;

endforeach;

$output .= '</ul>';

echo $output;

endif;

?>


But when i try and parse the PARENT parameter via the filter used for the taxonomy images it ignores it and displays all children.


Michael Caputo comments:

So shoudn't something like:


if($termID = $term->parent) :
echo '<a href="' . $termlink . '">' . wp_get_attachment_image( $term->image_id, 'gallery-thumb' ) . '</a>';
endif;


do the trick?

What output do you get when you run print_r($terms);


floy comments:

Are you referring to modifying the second block of code i sent through with the following?

if($termID = $term->parent) :

echo '<a href="' . $termlink . '">' . wp_get_attachment_image( $term->image_id, 'gallery-thumb' ) . '</a>';

endif;

2012-07-24

Hai Bui answers:

Please try this:


$terms = apply_filters( 'taxonomy-images-get-terms', '', array(
'taxonomy' => 'mycustomtaxonomy',
'term_args' => array('parent' => $termID)
) );


floy comments:

Hai Bui!
That did the trick! Before I end the question, can you give me a run down of why it has to be in in its own array to work? and will other parameters like this have to be parsed in the same array for term_args?


Hai Bui comments:

It has to be its own array to work because this plugin uses 'term_args' parameter as the second parameter when calling get_terms():
$terms = get_terms( $args['taxonomy'], $args['term_args'] );

Yes, other parameters for WP core function get_terms() must be in the same array, for example:


$terms = apply_filters( 'taxonomy-images-get-terms', '', array(
'taxonomy' => 'mycustomtaxonomy',
'term_args' => array(
'parent' => $termID,
'number' => 3
)
) );


floy comments:

That makes sense now! Thanks!