How can I use WP-CLI commands without –allow-root
You can do is to create an additional user and switch to it in order to use the wp-cli
You can do is to create an additional user and switch to it in order to use the wp-cli
Here’s a plan: Store the dates as individual custom fields with the same meta_key (ex: start_date) JOIN the wp_posts table with the wp_postmeta table, without a GROUP BY (to allow the same event to appear more than once) ORDER BY start_date The full query would look like this: SELECT wp_posts.*, meta_value AS start_date FROM wp_posts … Read more
There’s actually a better solution that will (hopefully) be rolling out in WordPress 3.4 — you can run the patch as a hotfix now if you’d like, but here’s the TRAC link for the patch: http://core.trac.wordpress.org/ticket/18158 With this, you can do … $my_query = new WP_Query( array( ‘meta_query’ => array( array( ‘key’ => ‘foo’, ‘compare’ … Read more
The following should work, but isn’t tested: <div id=”header-announcements”> <h3>Announcements</h3> <?php $queryObject = new WP_Query( ‘post_type=announcements&posts_per_page=5’ ); // The Loop! if ($queryObject->have_posts()) { ?> <ul> <?php while ($queryObject->have_posts()) { $queryObject->the_post(); ?> <li><a href=”https://wordpress.stackexchange.com/questions/26482/<?php the_permalink(); ?>”><?php the_title(); ?></a></li> <?php } ?> </ul> <div><a href=”#”>View More</a></div> <?php } ?> </div>
If you’re trying to get them to order by ascending price, the problem is that ordering by title is a string comparison, not numeric. A solution would be to put the price in a custom field and orderby your custom field rather than title. You would add a meta_key param with the name of your … Read more
Take a look at global $query_string;. Or var_dump( $GLOBALS[‘wp_query’] );.
Aha, despite there being a postmeta field of post_name->’slug’, the correct syntax (which mirrors that of WP_Query, is $args = array( ‘name’ => $postSlug, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’ ); $slugPosts = get_posts($args); Where ‘name’ is the key in the query (for posts, ‘postname’ for page). Doesn’t make much sense but might as well … Read more
Just inspect the current post content for ‘<!–nextpage–>’: function wpse_check_multi_page() { $num_pages = substr_count( $GLOBALS[‘post’]->post_content, ‘<!–nextpage–>’ ) + 1; $current_page = get_query_var( ‘page’ ); return array ( $num_pages, $current_page ); } On page 2 of 3 that returns: Array ( [0] => 3 [1] => 2 ) On an unpaged post it returns: Array ( … Read more
Sorting your posts by relevance This will need to add an extra propperty to each post. Than sort the object by this new prperty. The trick is to sort the posts directly in the query object. function get_posts(){ // get the posts but do NOT order them $query_posts = new WP_Query( array( ‘numberposts’ => 5 … Read more
The WP_Query page on the Codex has a section on Order & Orderby Parameters. If you want to order the query by a custom field you should add ‘orderby’ => ‘meta_value’ AND you must also specify the custom field (called your_date_field in the above example) using the meta_key key in the query. $timeline_query = new … Read more