Convert Featured products loop into Recent products loop?
Try this: $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 25, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ); $loop = new WP_Query( $args );
Try this: $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 25, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ); $loop = new WP_Query( $args );
Your loop is wrong, you should not use to foreach inside the while, simply add the classic the_post () using the variable of your loop in this case $ loop for example <?php $args = array( ‘post_type’ => ‘product’, ‘stock’ => 1, ‘posts_per_page’ => 9, ‘product_cat’ => $pagename, ); $loop = new WP_Query( $args ); … Read more
So if you’re getting the sticky-post you want removed anyways I want to do that coz I will make another query to render the latest sticky post on top of the main loop in a separate ‘div’ Just make a variable, $excludeSticky, with it’s ID, and add an ‘post__not_in’ => array($excludeSticky), argument in your query.
Problem solved! You need to change this part of code before 3rd query… it will merge you previous queries and exclude posts from them: $first_grid_posts_ids = wp_list_pluck( $first_grid_query->posts, ‘ID’ ); $second_grid_posts_ids = wp_list_pluck( $second_grid_query->posts, ‘ID’ ); $allTheIDs = array_merge( $first_grid_posts_ids , $second_grid_posts_ids ); $third_grid_query = new WP_Query( array( ‘posts_per_page’=>4, ‘post_type’ => ‘post’, ‘cat’ => get_query_var(‘cat’), … Read more
First you need to pass the post_id to this function to use the post_id inside the get_the_category($post_id) function incomplete_cat_list($post_id = ”) { global $post; $post_id = ($post_id) ? $post_id : $post->ID; $first_time = 1; $categories = get_the_category($post_id); foreach($categories as $category) { if ($category->cat_name != ‘Category Name’) { if ($first_time == 1) { echo ‘<a class=”cat-list” … Read more
You can do it with the pre_get_posts hook. In WP_Query there is an author parameter : https://codex.wordpress.org/Class_Reference/WP_Query#Author_Parameters pre_get_posts hook : https://codex.wordpress.org/Plugin_API/Action_Reference/pre_get_posts function wpse_288986_remove_post_from_author($query) { // We have to check if we are in front and if the query is the main query if(!is_admin() && $query->is_main_query() && is_archive()) { $query->set(‘author’, -2); // Where 2 is your … Read more
Use wp_dropdown_categories() to do so, I’ve addressed this before, here and here.
You can’t have code directly in the class definition. If you want it on instantiation, put it in the __construct function. Also, be aware that you were missing a semicolon and .= is used to append to strings, not to add to arrays. I’ve fixed those as well: <?php class myclass { private $arr = … Read more
As Milo hints at in their comment, custom post types can only be registered on the init hook. Therefore, if you are trying to get all the public but not builtin post types before init, then get_post_types() will return an empty array. (You can use get_post_types() to get the builtin post types before init.) What … Read more
I believe this has already been answered perfectly in How can I get only parent terms?. The solution is to set ‘parent’ => 0 when querying terms with get_terms() or WP_Term_Query. The example from that question looked like this: $myterms = get_terms( array( ‘taxonomy’ => ‘taxonomy_name’, ‘parent’ => 0 ) ); You can easily loop … Read more