skeg64
Forum Replies Created
Viewing 3 replies - 1 through 3 (of 3 total)
-
Forum: Fixing WordPress
In reply to: Automatically select ancestor terms for all selected termsThis revision provides better compatibility with plugins (doesn’t rely on POST data), and only updates custom taxonomies, not built-in ones.
add_action('save_post', 'jr_select_parent_terms', 10, 2); // automatically select parent terms function jr_select_parent_terms($post_id, $post) { if( $post->post_type == 'revision' ) return; $taxonomies = get_taxonomies(array('_builtin' => false)); foreach ($taxonomies as $taxonomy ) { $terms = wp_get_object_terms($post->ID, $taxonomy); foreach ($terms as $term) { $parenttags = get_ancestors($term->term_id,$taxonomy); wp_set_object_terms( $post->ID, $parenttags, $taxonomy, true ); } } }Hi,
Great patch. I would love to see:- the hierarchy preserved when using checkboxes
- an option to automatically select “ancestor” terms when a child term is selected
- option to only display top-level terms
Cheers
Forum: Plugins
In reply to: Solution to display one random Sticky PostI have improved the code to work on pages with multiple loops:
<?php $sticky=get_option(‘sticky_posts’); $randomStickyNo=0; $randomStickyNo=(rand()%(count($sticky))); $postno = $sticky[($randomStickyNo)]; $temp = $wp_query; $wp_query = null; $wp_query = new WP_Query(); $wp_query->query(‘p=’ . $postno); ?>
I was getting very strange behavior due to the multiple loops. Some browsers (Chrome, Firefox) would display the correct post, and IE6, IE7, Safari would return as “not found”.
Viewing 3 replies - 1 through 3 (of 3 total)