Tag Info

Hot answers tagged

7

You may be surprised, but there is nothing strange there. First of all let's clarify that in WordPress when you visit a frontend url you trigger a query. Always. That query is just a standard WP_Query just like the ones to run via: $query = new WP_Query( $args ); There is only one difference: the $args variable are generated by WordPress using the ...


2

category is a valid parameter for get_posts, not for WP_Query. Here are the valid category parameters for WP_Query cat (int) - use category id. category_name (string)- use category slug (NOT name). category__and (array) - use category id. category__in (array) - use category id. category__not_in (array) - use category id. You can use either use cat or ...


2

The $post global is set by $wp_query->the_post(). As $post is set by the main query and the fact that templates are set within the global variable scope, it is available throughout the template, so there is no need to explicitly calling the $post global when you are within the specified template as the WP_Post objects can be accessed any where. You can ...


1

Here are two ideas for your date_query part: 1) After 2 days ago: If you need posts published after current time, 2 days ago: 'date_query' => array( array( 'after' => '2 days ago', // or '-2 days' 'inclusive' => true, ), ), then the corresponding SQL part is: post_date >= '2014-09-09 17:57:15' if the ...


1

get_users_of_blog() is indeed deprecated and has SQL query hardcoded to sort by ID. You need to use modern get_users() function. It supports many arguments, including multiple ways to sort.


1

Take a look at PHP's array_values function. Alternatively, you could typecast. Note that if the array is in serialized form as you have put it above, you will have to unserialize it first, in either case. $numerical_array = array_values( unserialize( 'a:1:{s:8:"post-134";s:3:"134";s:8:"post-136";s:3:"136";}' ) ); or $numerical_array = ...


1

What describe is the way it should work: cat_id it is not a valid argument, so you get posts from all categories. Use cat to set one category ID or an array of categories ID. For example: Get posts from category 1: new WP_Query( array( 'cat' => 1 ) Get posts from category 1 and from category 2 (not in both necessarily) new ...


1

I am giving solution of my own problem :) <?php $descendant= array('child_of'=>54); $categories = get_categories($descendant); foreach($categories as $category) : echo $category->name; endforeach; ?>


1

Within the loop you have functions like: the_ID() or get_the_ID() that return $post->ID the_title() or get_the_title() that return $post->post_title the_content() or get_the_content() that return $post->post_content etc. But they apply filters and shortcodes for the post you are viewing. For more details on how these functions work visit the ...



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