only delete post within query / for each statement (front end)

You should pass in the id of the post you want to delete as an argument of the delete_post() function rather than relying on obtaining it via global $post within the function itself: <?php echo delete_post($section->ID); ?> Then in your delete_post() function you can use the passed-in argument like so: function delete_post($sectionid){ $deletepostlink= add_query_arg( ‘frontend’, … Read more

Five posts from a category in footer

First: don’t use query_posts. Second: use $wp_query instead: $args = array ( ‘category_name’ => ‘entertainment’, ‘posts_per_page’=> 5 ); $the_query = new WP_Query( $args ); if ( $the_query->have_posts() ) { echo ‘<ul>’; while ( $the_query->have_posts() ) { $the_query->the_post(); echo ‘<li>’ . get_the_title() . ‘</li>’; } echo ‘</ul>’; /* Restore original Post Data */ wp_reset_postdata(); } else … Read more

How to do meta_query for attachments?

I went with custom taxonomy instead of custom meta field and it works great (although I am still not sure why meta_query didn’t work) I have saved custom taxonomy term for each attachment wp_set_object_terms($post->ID, $slug, ‘image_category’ ); And custom query args are $args = array( ‘post_type’ => ‘attachment’, ‘posts_per_page’ => 44, ‘post_status’ => ‘inherit’, ‘post_parent’ … Read more

Wp_query returning only one post while query through ajax

You are resetting the $output value in the loop. Declare an empty variable first, and then append each result to it in the loop: if($posts->have_posts()){ $output=””; while ($posts->have_posts()) { $posts->the_post(); $output .= get_the_title(); } } This will add all the posts to the $output variable.

Ajax Pagination on Ajax filter

As @Milo brilliantly pointed out, there is no such a thing like a global query object in WordPress. So I’ve solved the problem via JS, like this: var isFiltered = false; var filters; $(load_more_button).click(function(e) { load_more_handler(e); }); $(filters_form).submit(function(e) { filter_handler(e); }); function filter_handler(e) { isFiltered = true; filters = $(this).serialize(); var data = { action: … Read more

How to use MySQL’s MATCH AGAINST in WP_Query?

As far as I know, you can’t use MATCH()… AGAINST in WP_Query. The possible values for comparison are the following: = != > >= < <= LIKE NOT LIKE IN NOT IN BETWEEN NOT BETWEEN NOT EXISTS REGEXP NOT REGEXP RLIKE Which the default is =. However, you can use MATCH() AGAINST in a generic … Read more

Orderby ASC changes to DESC in WP_Query

You’ve made “orderby” and “order” part of the date_query sub-array. “Order” parameters belong to the main parameters array. I can’t vouch for the part of your code that concerns the year and the above-undefined variable $ppy, but if you want the posts from a specified year in ascending order by ‘post_date’ (which is the default), … Read more