How to store the_title() into a variable to reutrn the value, not just echo it
You can use get_the_title() to return the current post title in the loop.
You can use get_the_title() to return the current post title in the loop.
Using get_sites() in WP 4.6+ It looks like wp_get_sites() will be deprecated in WP 4.6. The new replacement is: function get_sites( $args = array() ) { $query = new WP_Site_Query(); return $query->query( $args ); } Very similar to get_posts() and WP_Query. It supports various useful parameters and filters. Here’s what the inline documentation says about … Read more
This is a stupendously expensive query, you can mitigate but you can’t eliminate the performance issues. So lets start with the low hanging fruit and work our way up to the big problems posts_per_page Always set a maximum, even if it’s one you never expect to reach. -1 is asking for trouble: There’s no upper … Read more
I figured out what I was doing wrong. A simple beginners mistake. Array_reverse was working properly, but I wasn’t then reassigning the reversed array back to the $home_shows WP_Query, hence not seeing any change. Here is the answer, and my revised code. <?php $args = array( ‘post_type’ => ‘show’, ‘posts_per_page’ => 5, ‘order’ => ‘DESC’, … Read more
Normally you would just specify a meta_value, e.g.: $args = array( ‘post_type’ => ‘business’, ‘meta_query’ => array( array( ‘key’ => ‘specials’, ‘value’ => ‘these are not the specials you are looking for – Obi Wan Kenobi’ ) ) ); However because your post meta is actually a data structure, a serialised PHP array/object, that’s not … Read more
@EAMann’s answer is correct, but there’s already a build in WordPress function for fetching all registered post types: get_post_types <?php // hook into init late, so everything is registered // you can also use get_post_types where ever. Any time after init is usually fine. add_action( ‘init’, ‘wpse34410_init’, 0, 99 ); function wpse34410_init() { $types = … Read more
use post__in key instead of include to get posts from the specific post ids. $args = array( ‘post_type’ => ‘testimonials’, ‘posts_per_page’ => 4, ‘orderby’ => ‘ID’, ‘post__in’ => array(883, 563, 568, 106), ); And to order posts by the given posts ids, you can use the following array. $args = array( ‘post_type’ => ‘testimonials’, ‘posts_per_page’ … Read more
Seems like a silly question, but are there exactly 2 users in the database? Or are there more. The only thing I can see happening is because you are setting to 3, it’s looping back through. Another thing to try is checking the peterpanpan user, to see if he has the custom_role twice in his … Read more
I created a Kint plugin that works really well. I also integrates with the Debug Bar plugin. You can download it at: http://wordpress.org/extend/plugins/kint-debugger/ There are a few functions to help you out with WordPress specific globals: dump_wp_query() dump_wp() dump_post() For printing arrays in a styled, collapsible format you would do the following. $foo_bar = array( … Read more
Filters work by calling each of the hooked callback functions (in priority order). The value to be filtered is passed to the first callback funtion. The returned value of that callback function is then passed to the second callback, and the returned value from that is passed onto third and so on, until all hooked … Read more