Tag Info

Hot answers tagged

6

use 'post_parent' => 0 in WP_Query to return only parent posts


4

This should work, using nothing more than the available argument-array parameters for wp_list_pages(): specifically, depth and child_of. To display one level of hierarchy, for descendant pages of the current page: <?php // Globalize the $post variable; // probably already available in this context, but just in case... global $post; wp_list_pages( array( ...


4

I don't have the data to test so the code below may be wrong. add_filter('posts_search', 'set_is_tax_to_true' ,10,2); function set_is_tax_to_true($search,$query){ $query->is_tax = true; } $args = array( 'post_type' => 'attachment', 'posts_per_page' => -1, 'post_status' => 'pending', 'post_parent' => $post_id, 'order' ...


4

Great answers above. I took on the challenge trying to find yet another way to solve this. The exclude parameter: We could try: 'exclude' => wpse_exclude_drafts_branches() where: function wpse_exclude_drafts_branches() { global $wpdb; $exclude = array(); $results = $wpdb->get_col( "SELECT ID FROM {$wpdb->posts} where post_status = ...


4

Sincerly I found custom walkers annoying: sometimes what can be done with a simple filter require an entire class to coded and, but probably it's me, I don't really like logic behind WordPress walkers. This is the reason why I often use a trick to filter elements before they are walked. It is a really simple Walker class: class FilterableWalker extends ...


3

Making use of a custom Walker is actually not that hard, it basically goes like this: Create a class; A class is a collection of variables and functions working with these variables. By extending another one; The extended or derived class has all variables and functions of the base class [...] and what you add in the extended definition. ...


3

Firstly, it should be post_excerpt. Secondly, this just stores the manually added excerpt, so it returns empty if you don't have one. Thirdly, you could setup_postdata: <?php $pagechildren = get_pages( array( 'child_of' => $post->ID ) ); ?> <?php foreach ( $pagechildren as $post ) : setup_postdata( $post ); ?> // code ...


3

First of all, you should not be using query_posts to run custom queries. From the codex itself Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with ...


3

I have a suspicion that you've fallen into a misunderstanding a lot of new users fall into, but rarely realise. I suspect you have done this: This is bad, and suggests a lack of understanding about how categories work. It will also cause issues in your code when your assumptions don't match the reality of things. But don't worry, everyone makes this ...


3

Code based in Bainternet's answer to this question: Make Categories and Tags required in admin See code comments. add_action( 'admin_head-post-new.php', 'wpse_59770_publish_admin_hook' ); add_action( 'admin_head-post.php', 'wpse_59770_publish_admin_hook' ); add_action( 'wp_ajax_wpse_59770_pre_submit_validation', 'wpse_59770_ajax_pre_submit_validation' ); ...


3

I guess this function is what you are looking for -> get_ancestors()


3

Assuming you know (or know how to get) the $id (as an integer) of the parent post, use the post_parent parameter: $albums = new WP_Query(array( 'post_type' => 'gallery', 'posts_per_page' => 6, 'post_parent' => $id )); Edit Based on this comment: I don't know the parent post. I want to list the most recent child pages from ANY ...


2

You can't just pass the string "parent" to get_categories. You have to pass the ID of the parent. $categories=get_categories( array( 'parent' => $cat->cat_ID ) ); Notice that there are two similar but not equal "get child" parameters that you can use. child_of (integer) Display all categories that are descendants (i.e. children & ...


2

You can get a random post by category by using the following code: query_posts( array ( 'showposts' => 1, 'orderby' => 'rand', 'cat' => $cat->term_id ) ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ... And then use get_the_post_thumbnail() to retrieve the post featured image: if ( has_post_thumbnail() ) ...


2

Well, you can use the depth argument to control how many levels deep you want to show, and I've created a SubMenu walker, which displays the menu starting from the direct children of the current page. Code: class My_Walker_Submenu extends Walker_Nav_Menu { function display_element($element, &$children_elements, $max_depth, $depth = 0, $args, ...


2

I am not sure if querying the categories again is the good idea. The following code extends the Walker_Category and makes use of it to do the replacement. Put the following in your functions.php: class WPSE67791_Walker_Category extends Walker_Category { public function start_el(&$output, $category, $depth, $args) { parent::start_el( ...


2

as far as I know, all menu items already have unique ID´s ("menu-item-XX"), may they be first or second level. the UL itself has a different class : menu for first level and sub-menu for second. hence , in css for example .menu li and .sub-menu li will give you the differentiation for styling. you could also do that without the unique id or classes , by ...


2

Alright, after a couple more hours I removed the 'query_var' => '', and re-saved/flushed my permalink settings. Query_var defaults to true, and it works. Coding blindness or something lol. Hope this can help someone else.


2

Try it like this: $args = array( 'post_parent' => $parentid, 'post_type' => 'custom-type' ); $posts = get_posts( $args ); if (is_array($posts) && count($posts) > 0) { // Delete all the Children of the Parent Page foreach($posts as $post){ wp_delete_post($post->ID, true); } } // Delete the Parent Page ...


2

// inside your callback function: static $ancestors = null; $parent = (int) $comment->comment_parent; // Modify INITIAL VALUE here: $init_val = (int) 1; $is_child = false; if ( $parent > (int) 0 ) { $is_child = true; $ancestors[] = $parent; $child_counter = count( $ancestors ) + $init_val; } /* * Only needed in case you want to reset the ...


2

Simply put: no. If you want dynamic updating of your menu items, you would probably be better-served using wp_list_pages() or wp_page_menu().


2

possibly with get_terms() and the 'parent' parameter: http://codex.wordpress.org/Function_Reference/get_terms


2

The child ul comes with the class "children", so you can use this to target your css. ul.children li { } Even without that, though, you could just use the hierarchy of lists to target.. ul#catList ul li { } would target any li within a ul, within the #catList ID.


2

You are using get_categories() function and this function have not 'depth' argument. Also php is not supporting $cat-id variable. it would be $cat_id. So try this kind of code: $cat_id = get_query_var('cat'); $args=array( 'parent' => $cat_id, 'hide_empty' => 0, 'orderby' => 'name', 'order' => ...


2

Strictly speaking, according to the Template Hierarchy, you cannot. Unfortunately taxonomy-$taxonomy-$term-$subterm.php is not provided for in default, so this file structure will not work. The best you can do here is taxonomy-$taxonomy-$term.php So for Thailand you will name your template as follows taxonomy-location-Thailand.php EDIT Just ...


2

Add the following to your theme's functions.php: /** * Tests if any of a post's assigned categories are descendants of target categories * * @param int|array $cats The target categories. Integer ID or array of integer IDs * @param int|object $_post The post. Omit to test the current post in the Loop or main query * @return bool True if at least 1 of ...


2

This is the walker I used to display only children of the current menu item. Or the menu items siblings if it doesn't have any children of its own. There are comments throughout the class explaining each section <?php class SH_Child_Only_Walker extends Walker_Nav_Menu { private $ID; private $depth; private $classes = array(); private $child_count = 0; ...


2

I think you're confusing WP_Query with taxonomy arguments. WP_Query doesn't have a child_of argument, use post_parent. and sort_column should be orderby.


2

To add arrow for parent elements: jQuery + CSS Solution: JQUERY: jQuery(function($){ $(document).ready(function(){ $('ul.sub-menu').parent().addClass('drop-down'); // Add Sub-Menu Class to insert personalized style $('li.drop-down > a:first-child').wrapInner('<span class="menu-bullet" />'); // Add .menu-bullet in span to insert your ...


2

Thanks to @Rarst for guiding me to the right direction. Using his direction I googled again and again and found a blog article of WerdsWords with an excellent bit of code snippet filtered to category_template as Rarst suggested me, and the good news is: it worked for my cause: function new_subcategory_hierarchy() { $category = get_queried_object(); ...



Only top voted, non community-wiki answers of a minimum length are eligible