Hot answers tagged

2

WordPress will cache all terms for taxonomies attached to all post types in the query result set by default - well, so long as you haven't set either cache_results or update_post_term_cache to false (codex). So calling get_the_terms etc. within the loop will not hit the database. However, wp_get_object_terms will hit the database as it by-passes WordPress' ...


2

If I've understood your intentions correctly here, you don't need to use the meta_value argument at all. If you are just wanting to order by this meta_key but not filter which results are returned - i.e. you want to return the results from all the 'star' values - then providing the meta_key and the orderby arguments will get you there. There is no need for ...


2

I think you should be able to do this with the user_has_cap filter. Because that filter passes through the post ID in the $args for the edit_post capability, you can use that to check if the current user has been artificially given this capability - and if so, force the edit_post capability to be true for that instance. Building from the example in the ...


2

There is no order_by. Change order_by to orderby and it should work. The default value of compare is = so it is unnecessary, you can remove it. Also, you should specify type of the meta_value if it is a specific type rather than the default CHAR.


2

Here's one way by using wpdb::get_col() and fetch the id column: $pids = $wpdb->get_col( "SELECT id FROM my_table" ); We could then clean it by integer convert each id with: $pids = wp_parse_id_list( $pids ); Just note the different max value for intval(), depending on 32 or 64 bits systems.


2

post__in accept array of post IDs e.g. array(5, 4, 8, 9); Extending @bravokeyl comment. By default result is Object. As codex suggest you can change the output type of get_results() to these values. OBJECT - result will be output as a numerically indexed array of row objects. OBJECT_K - result will be output as an associative array of row objects, ...


2

There are many globals that are being set in a loop, not only $post, and you need to set all of them to get exactly the same behavior. To get this it is not enough to set $post but you also need to use setup_postdata


1

Give something like this a try: (it came from the same page you linked to, just scroll down a bit more). $args = array( 'post_type' => 'post', 'tax_query' => array( 'relation' => 'AND', // searches for posts meeting both conditions array( 'taxonomy' => 'midgets', 'field' => 'slug', 'terms' => array( ...


1

Your code is invalid (syntax error, missing closing array and semi-colon), and incorrectly nested - if you were to properly indent your code, you'd have something like: $args = array( 'tag' => 'tag-AAA,tag-BBB', array ( 'orderby' => array( 'title' => 'ASC', 'post_date' => 'DESC', ...



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