Articles of wp query

Improving WP_Query for performance when random posts are ordered

I have made a new query after I’ve asked a question about my query_posts code… you guys didn’t find that great, so I decided to change that. I made this: $page = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; $rand = new WP_Query(“showposts=10&orderby=rand&paged=$page”); while($rand->have_posts()) : $rand->the_post(); My question is: how can I improve this? Isn’t it better […]

How to get post category list as select in front-end?

I use widget plugin Getting the random post & URL via ajax. I want to add function, that allows users on frontend choose category, and than display random posts from this category. function get_random_post_tu() { // Simple as that, get a random post $posts = get_posts(‘orderby=rand&numberposts=1’); /** * This actually gives us an array of […]

Pagination Not working on Home Page with 2 Query

I have two loops in home page (index.php) <?php $args = array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 3, ); $another_query = new WP_Query($args); if( $another_query->have_posts() ) { $i = 0; while ($another_query->have_posts()) : $another_query->the_post(); ?> <?php if($i == 0) { ?> <div class=”col s8″> <?php get_template_part( ‘template-parts/content-magazine-grid-big’, get_post_format() ); ?> </div> <?php } ?> <?php […]

WP Meta Query for some meta (array) values

If I get my posts using meta_query by ‘my_meta_key’ only I get something like this Array( [0] => Array( [nested_key1] => something_I_want1 [nested_key2] => something_I_want2 [dont_care_key] => something_I_dont_care_about ) [1] => Array( [nested_key1] => something_I_want1 [nested_key2] => something_I_DONT_want [dont_care_key] => something_I_dont_care_about ) ) Now I would like to do a meta_query, that would only fetch […]

Loop categories by recent post

Im looking for a way to loop through categories and then display the recent posts for each one in a container but I need a way to sort the categories by which ones have the most recent posts So if Category C has a more recent post then it’ll appear first before Category A $args […]

Changing a theme's search function to only show results from woocommerce?

I am very new and trying to learn as I go. I bought a premium theme from themeforest, without checking the functionality of various pages. Tried their support with no solution offered. Now I am looking at the code with very little knowledge about it. Still trying to learn. Can someone help me with this […]

How to get CPT category checkbox list and show post of selected(multiply) checkboxes via ajax?

I want to create a plugin that outputs Custom Post Type category checkbox list(as in back-end WordPress) to show CPT posts that contain selected on front-end categories(multiply select) after pressing a button with ajax(without reloading). I took plugin Getting the random post & URL via ajax and modify it, but something is wrong. In this […]

Nested array issue in meta_query

I am using following meta_query to search blog post according to following search criteria, search logic : if expire date set, check the expiry of the post, otherwise just include it if country($_country) in the filters, search for that particular country with above expire date rule. otherwise just apply the expire date rule. meta_query: $expire_meta_1 […]

WP_Query with page_ids in arguments without a result

I want to get some pages with WP_Query: $resume_args = array(); $resume_args[‘post_type’] = ‘resume’; $resume_args[‘posts_per_page’] = -1; //$resume_args[‘page_id’] = array(9046, 9346); //No results! $resume_args[‘page_id’] = 9046; //Works fine $resume_args[‘s’] = ‘gassi gehen’; $resumes = new WP_Query($resume_args); But if I use for [‘page_id’] an array I don’t get any results. If I only use one page_id […]

Conflict array_splice on loop and query in widget

I am using the function array_slice to insert two post within the loop in the index. function insert_post_wpse_96347($posts) { global $wp_query; $args = array(‘meta_key’ => ‘Caja’, ‘meta_value’ => array(‘UNO’,’DOS’), ‘post__not_in’ => get_option(“sticky_posts”), ‘posts_per_page’ => ‘2’,’suppress_filters’=>true); if (is_main_query() && is_home() && 0 == get_query_var(‘paged’)) { $p2insert = new WP_Query($args); $insert_at = 0; if (!empty($p2insert->posts)) { array_splice($posts,$insert_at,0,$p2insert->posts); […]