Tag Info

Hot answers tagged

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

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

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


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

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

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


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

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

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

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


1

As the OP never moved it to an answer and someone commented that he closely missed that there was a solution, I moved it to this answer. To the OP: Please repost this answer as your own, mark it as solution and leave a comment on this answer so I can remove it. Finally hours later, i have something that is working. I'm thinking this isn't the best way to ...


1

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


1

You have so many things wrong with your code, to start WP_Query does not have 'sort_column' , or 'depth' parameters. the use of $do_not_duplicate = $post->ID; does nothing at all and a few other things. What you need is to get the children (just the ids, no need to get the post object since you are not using any of the fields other then title and ...


1

I just figured out the answer to my own question. It works by counting the number of children pages using get_pages. Here is the working code: <?php $children = get_pages( array('child_of' => $post->ID,'post_type'=>'custom-post-type-name')); if( count( $children ) != 0 ) { ?> <h1><a href="<?php the_permalink(); ...


1

If you don't have to use query_posts() then this is one method: function my_menu() { global $post; if(!$post->post_parent){ // will display the subpages of this top level page $children = wp_list_pages( array( 'title_li' => '', 'child_of' => $post->ID, 'echo' => 0 ) ); } elseif($post->ancestors){ // ...


1

try -: if your page ID = 999 <?php $child_ids = $wpdb->get_col("SELECT ID FROM $wpdb->posts WHERE $wpdb->posts.post_parent = 999 AND $wpdb->posts.post_type = 'page' AND $wpdb->posts.post_status = 'publish' ORDER BY $wpdb->posts.ID ASC"); $exclude = implode($child_ids,', '); wp_list_pages('exclude=' . $exclude . ...


1

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


1

Great hack, it did what I was looking for. I thaught some of you might be interrested in what I added, that is: alternative links to the first child page when you are browsing the parent page to the parent when you are browsing the first child page the nav is not displayed when not necessary, the styling fits the one the twenty-thirteen theme applies ...


1

You shouldn't have any problem making parent and child categories look different using CSS. Go to view source and you should see something like: <ul id="catList"> <li class="cat-item cat-item-1"><a href="http://yourdomain.com/category/misc/" title="Miscellaneous and Unsorted Posts">Misc.</a> (1) </li> ...


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

You can use get_query_var( 'term' ) to get the current term and get_query_var( 'taxonomy' ) to get the current taxonomy, then all that is left is to use [wp_dropdown_categories()][1] function withchild_ofparameter andtaxonomy` parameter, so something like this: //first get the current term $current_term = get_term_by( 'slug', get_query_var( 'term' ), ...


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

I think you need to use depth=1 rather than depth=2. You are specifying, via the child_of argument, that you want to display children of the current Page's parent Page. That means that the first level of hierarchy is the current Page (and any of its siblings). The second level of hierarchy would be child pages of the current Page (and of any of the current ...


1

POST does not have parents, but categories. Only PAGE can have parent. So, the question is, what do you want to get? In case of getting POSTS from different categories, just use get_posts and add multiple categories. As for pages, just use get_page_children.


1

OK, I almost got it now... I extended the Walker_Page Class: class Walker_Child_Classes extends Walker_page { function start_el(&$output, $page, $depth, $args, $current_page) { if ( $depth ) $indent = str_repeat("\t", $depth); else $indent = ''; extract($args, EXTR_SKIP); $output .= $indent . '<li class="' . apply_filters( 'the_title', ...


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