Tag Info

New answers tagged

2

I agree with Rarst about the WEEK function, but be sure to also use YEAR as well to order the posts. So your order by would look something like this: ORDER BY YEAR($wpdb->posts.post_date) DESC, WEEK($wpdb->posts.post_date) DESC, $wpdb->postmeta.meta_value+0 DESC Of course, this is still pulling all posts, so you might also want to just limit the ...


1

This is more of an MySQL question than WordPress one. You are already using date functions there, from a quick check there is (unsurprisingly) one for WEEK(date[,mode]), you could use in similar fashion for order.


1

You could do it for example like this: function wpse182116_get_categories_starting_with($word) { $categories = get_categories(); if (!empty($categories)) { $relevant_ids = array(); foreach($categories as $c) { $cat_name = $c->name; if(substr($cat_name, 0, strlen($word)) == $word) { $relevant_ids[] = ...


0

You can try this code below $args = array( 'orderby' => 'name', 'order' => 'ASC', 'name__like' => '%LIKE%', 'description__like' => '%LIKE%', ); $terms = get_terms( array( "taxonomy" ), $args ); See more in Codex


0

The global $wp_query (in this case its the $query var) holds the $current_post which is available in the loop and tells the index of the current post ( $wp_query->current_post ). The $wp_query->post_count tells the number of posts being displayed in the loop, and this actually becomes a simple arithmetic solution that will work no matter how many posts the ...


0

You are running two queries in one. You should only run one, and definitely not with query_posts. You should never ever use query_posts Note: This function isn't meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify ...


0

I figured it out <?php $args = array( 'post_type' => array('post', 'music-videos'), 'posts_per_page' => 5, 'orderby' => 'menu_order post_date', ); $loop = new WP_Query( $args ); ?> <div id="example1" class="slider-pro"> <div ...


-1

You could get the categories and for each of them, you use the list category posts plugin shortcode to echo the relevant posts into a div: $categories = get_categories(); foreach ($categories as $category) { echo '<div>'; $cat=$category->cat_name; echo do_shortcode( '[catlist id='.$cat.' numberposts=5 ]'); ...


-1

You have placed minus sign before the parameter. This only work for inclusion of post. For exclusion you have to use like this query_posts(array('posts_per_page' => 10, 'post__not_in' => array(1,3,5))); Check this in Wordpress Codex


1

If you are trying to omit posts 1,3,5 from category 3 on your blog, you can use the following code $query = new WP_Query( array('cat' => 3, 'post_type' => 'post', 'post__not_in' => array(1,3,5) ) ); The query results will not show posts with ids 1,3,5 of category 3.


0

Thanks to Rarst's guidance I put together a quick solution that seems to do the trick even though it seems a bit hacky. Solution: page.php <?php $two_posts = new WP_Query(array( 'nopaging' => true, 'post_per_page' => -1, 'post_type' => 'post', 'post__in' => array(1, 2), 'orderby' => ...


1

First, don't use is_main_query() function (method is ok). It tells something absolutely different from what you would think it does — was the main query overridden. As far as I remember, there is no clean solution to this since WP doesn't have a concept of explicitly passing context to a specific template or template part. Since WP's way hinges primarily ...


1

I would rather use a full proper tax_query here. The {tax} syntax is depreciated according to the docs A tax_query is also better here as you will be dealing with an array of terms. When your URL is http://www.myWebsiteURL.com/lessons this means that all terms should be displayed. So this means that you need to use the full $validCats array as query ...


0

If you want best practices of the options you listed use the user meta table. Adding a column to the users table would be the worst thing you could do - messing with table structure of default WP tables is a no-no. The other two options would fall somewhere in between - with adding your own table being least preferred. But why don't you use the ...


0

Note that this part: 'post_status' => 'published', should be: 'post_status' => 'publish', You can then try the following: $args = array( 'post_type' => 'gutschein', 'pagination' => true, 'posts_per_page' => '10', 'posts_per_archive_page' => '10', 'ignore_sticky_posts' ...


0

I think the problem may be with your wildcards. Because you're trying to use Wildcards in the prepare, which takes %s, the WPDP doesn't know the difference between the wildcard % and the placeholder %. Using this answer as reference: How to use wildcards in $wpdb queries using $wpdb->get_results & $wpdb->prepare? You'll have to double-escape the ...


0

Try this: $args = array( 'post_type' => 'post', 'posts_per_page' => 3, 'meta_key' => 'post_views_count', 'orderby' => 'meta_value_num', 'order'=> 'ASC', 'date_query' => array( array( 'after' => '30 days ago' ), ), ); $query = new WP_Query( $args ); You can't directly order by ...


0

If you still want to do that by $wpdb please try this.. <?php global $wpdb; $query = "SELECT p.*, terms.term_taxonomy_id, terms.term_id, terms.slug, terms.name from $wpdb->posts p INNER JOIN ( SELECT rel.object_id , rel.term_taxonomy_id, term.term_id, term.name, term.slug FROM $wpdb->term_relationships rel INNER JOIN ...



Top 50 recent answers are included