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

query private custom post type

If you are setting the CPT to private, that is telling wordpress not to create the dynamic page for that post type. This includes using the single-CPT.php file. If you want to have “?post_type=” pages, you’ll need to set the cpt to publicly_queryable=true, or public=true (which includes publicly_queryable). Why do you want it private (aka … 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