WordPress show posts from children terms of a taxonomy term
WordPress show posts from children terms of a taxonomy term
WordPress show posts from children terms of a taxonomy term
First of all you want to add it only once, so you have to check if it exists. Then you can use wp_insert_term function if ( !term_exists(‘MyCategory1’, ‘genre’) ) { wp_insert_term(‘MyCategory1’, ‘genre’); }
Few remarks: I use pre_get_posts as an action hook, not as a filter. You should use ! is_admin() to prevent this from changing your backend views. You should skip the ‘relation’ => ‘OR’, since you only have a single tax_query filter Is there any reason why you have to modify the post type ? Is … Read more
Retrieve name or slug from get_objects_in_term
There’s no such thing as a taxonomy archive. There is a taxonomy term archive, but no taxonomy archive. E.g. this URL makes no sense in the current system: example.com/category/ But this does: example.com/category/uncategorised/
displaying links if term is used
This should work, but it’s not tested <div id=”tabs”> <ul id=”tab-menu”> <?php $terms = get_terms(‘category’); global $wpdb; $posts = array(); if ( is_array($terms) && ! empty($terms) ) { $active = null; foreach ( $terms as $i => $term ) { $ids = $wpdb->get_col( $wpdb->prepare(“SELECT object_id FROM $wpdb->term_relationships WHERE term_taxonomy_id = %d”, $term->term_taxonomy_id )); $articles_count = … Read more
Use brackets in the name attribute: ‘<input type=”checkbox” name=”t[‘ . $term->name . ‘]” value=”1″> Then get the keys with: array_keys( $_GET[‘t’] ); See also: Settings API with arrays example
In your loop use has_term( $term, $taxonomy, $post ). Check if the post has the term you are searching for. Check if there is a value for the custom field. Print the value, but don’t forget to escape it. if ( has_term( ‘blue’, ‘product_color’, $post ) ) { $field = get_post_meta( $post->ID, ‘field_name’, TRUE ); … Read more
Just add $my_query[‘posts_per_page’] = 10; (or some other number) before query_posts call. But I’m not sure if I understand you correctly.