Tag Info

Hot answers tagged

6

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


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' ...


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

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 ...


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 ...


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

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

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

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

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


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

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

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

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

// 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

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( ...


1

For actual categories: <ul> <?php global $post; // grab categories of current post $categories = get_the_category($post->ID); // define arguments of following listing function $args = array ( 'child_of' => $categories[0], // current post's (first) category 'title_li' => '' // disable display of outer ...


1

According to the codex for WP_Query, the solution might be to use the post_parent as the id of the top level post. But as there are a whole lotta top level cpts in your case, I think this solution should help you: How to display only top level posts in loop via WP_Query?. Update: <?php $all = get_posts(array('post_type'=> 'city', 'posts_per_page' ...


1

What you want, I think, is the posts_where filter, which allows you to add additional WHERE clauses to the SQL query that get_posts generates. This will save you the trip to the database to fetch only parent posts. The hooked function will receive two arguments: the WHERE clause itself and the query object. Check to see if the query is for the city post ...


1

The correct syntax of cat_is_ancestor_of is cat_is_ancestor_of( $parent_cat_id, $child_cat_id ); Where: $parent_cat_id: should be the id to check if this is the parent category, in your case it should be 526. $child_cat_id: should be the id of the child category.


1

You could maybe choose to use a tree like that: Fruits Color1 Apple Watermelon Color2 Banana Lemon Level1 Level2 Level3 This way, you can, in your theme, hide the second level. Hope that helps.


1

Instead of: $args = array( 'order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'attachment', 'post_parent' => $post->ID, 'post_mime_type' => 'image', 'numberposts' => 1, ); Use: $args = array( 'order' => 'ASC', ...


1

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, ...



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