Hot answers tagged

11

If you want display an image that is inserted into your content (a hotlinked image, for example), you must use a function like this (source): add in functions.php: function catch_that_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->...


7

Are you sure you need this specific function? Documentation (both Codex and inline) is verrry confusing. And it supposedly fetches things like attachments, which probably aren't relevant for navigation... Try this: get_posts( array( 'post_type' => 'page', 'post_parent' => $parent->ID, 'orderby' => 'menu_order' ) );


5

There's also a generic WP possibility to do this via get_term_children. <?php $children = get_term_children($termId, $taxonomyName); if( empty( $children ) ) { //do something here }


5

There may or may not be a better way to do this, but here's how I would do it: $term = get_queried_object(); $children = get_terms( $term->taxonomy, array( 'parent' => $term->term_id, 'hide_empty' => false ) ); // print_r($children); // uncomment to examine for debugging if($children) { // get_terms will return false if tax does not exist or ...


3

The problem There's on (imho) serious issue with WordPress and Taxonomies and their term hierarchy (and children): They aren't really fetched from the actual state, but someone who thought (s)he might be really "smart" stuffed that into the *_options table. Just take a look at the source of get_term_children(): It makes a call to _get_term_hierarchy(). ...


3

There isn't much overhead, you're hitting the database anyway. Just use array_map. function get_titles($n) { return($n->post_title); } $titles_only = array_map("get_titles", $projects_children ); As for limiting and ordering, check out the Pagination Parameters (posts_per_page) and Order & Orderby Parameters of WP_Query. Note: code is ...


3

The 'orderby' argument should work with get_children() because get_children() is really just a wrapper around get_posts() with a different set of defaults. The menu order refers to the Order specified in the Page Attributes meta box when editing a Page... not to the order you've sorted a custom menu into.


2

Looks like this is two questions: how to get all the children that are audio, and how to get all the children that aren't audio. 1) The post_mime_type parameter of get_children can actually take a wildcard, so you could use: $children = get_children(array( 'post_parent' => $post->ID, 'post_status' => 'inherit', 'post_type' => '...


2

I suggest two ways: Using a Plugin I would consider using the Get The Image plugin, so you could do something like: $args = array( 'post_id' => <id> 'image_scan' => true ); get_the_image($args); The above will try to do things in this order: Look for the post thumbnail Look for the first attached image Scan the post content for a ...


2

the code seems perfectly safe. like you said, you don't have any image attached to the post. Consider going to the media admin panel and attach a image to that post. Alternately, scrap the post content with a regex for images in it.


2

What about: $taxName = "tvr_amenity"; $terms = get_terms($taxName,array('parent' => 0)); foreach($terms as $term) { echo '<a href="'.get_term_link($term->slug,$taxName).'">'.$term->name.'</a>'; $term_children = get_term_children($term->term_id,$taxName); echo '<ul>'; foreach($term_children as $term_child_id) { ...


2

We can filter the generated SQL query through the terms_clauses filter before the SQL query is executed. What we will be doing is to introduce a new parameter called wpse_parents which will accept an array of parent term ID's to get children from. Note, this new parameter works exactly the same as the build-in parameter, parent, as it will return only direct ...


2

You could use the get_post_galleries_images function, which returns an array of all the galleries from whatever post ID you specify. The following is a quick function that will display all the images: function na_get_gallery_image_urls( $post_id, $number = false ) { $post = get_post($post_id); $count = 0; // Make sure the post has a gallery in ...


2

This can be approached by using wp_dropdown_pages() with the child_of parameter. global $post; $args = array( 'child_of' => $post->ID ); wp_dropdown_pages( $args ); The variable name will be $_GET['post_id'] or $_POST['post_id'], depending on your form settings, you can change the name by altering the name parameter. The value of the ...


2

First of all you should alway separate php from javascript. Generally talking, it's a bad practise mix them, and specifically to WordPress, it also force you to add javascript inline instead using the WordPress proper way: using wp_enqueue_script. When you need pass variables from PHP to javascript, the proper WordPress way to do it is using ...


1

The woocommerce function get_categories() is declared in abstract-wc-product.php, because it is based on the wordpress function get_the_term_list() there is no way to get only a specific branch of a category. This absolutely isn't the same as the wordpress function get_categories(), you can see that it is woocommerce specific by how it's used $product->...


1

Use the get_terms() function instead: $term_children = get_terms( 'mytaxname', array( 'parent' => get_queried_object_id(), ) ); if ( ! is_wp_error( $terms ) ) { foreach ( $term_children as $child ) { echo ' <div class="product-archive"> <div class="post-title"> &...


1

You can use for example very basic WP Query (or get_pages or what ever. this is just one example) (http://codex.wordpress.org/Class_Reference/WP_Query) // The Query $currentPageId = $post->ID; // get current page id inside loop $args = array( 'post_parent' => $currentPageId, 'post_type' => 'page', 'posts_per_page' => -1 ); $...


1

A quick experiment with WordPress 3.5.1 shows that when you an image into post from URL, there's no post inserted into the wp_posts or wp_postmeta table - which is why the $images array is coming back empty. You could write some JS on the admin side to create and insert a post asynchronously when you click the insert into post button - otherwise, you could ...


1

You can just return the IDs, then get each title by the respective ID. And to restrict the query to four posts only, you can use posts_per_page. I modified and optimized your above code a bit, so here it is: <h3>Recent Projects</h3> <ul class="footer-list"><?php $projects_page = get_page_by_title('Projects'); $args = array( ...


1

I know this is an old post but it may help someone $mime_types = get_allowed_mime_types(); $remove_mime_types = array( // Image formats 'jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png', 'bmp' => 'image/bmp', 'tif|tiff' ...


1

a) If you have reordered the images under the uploaded to this post in the media browser then they should have menu_order>0 and you can get that order with 'orderby' => 'menu_order', 'order' => 'asc' b) If you haven't, then menu_order=0 for all these images and you will need to use 'orderby' => '...


1

Following WordPress 3.5, gallery shortcodes now include the image IDs by default. Like this [gallery ids="729,732,731,720"] which also holds the order, so open the plugin file named carousel-gallery-jquery.php and replace this line: (around line 140) $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => ...


1

They give you an example on that page by using WP_Query to query for all pages, then get_page_children just filters that list. the "without using SQL queries" part is a bit of a misnomer, since you have to have already queried the database at some point to get those pages. if you don't already have a result to filter, then something like get_children or ...



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