How do I sort this custom list of sticky posts

This should do the trick: $sticky = get_option( ‘sticky_posts’ ); $args = array( ‘posts_per_page’ => -1, ‘post__in’ => $sticky, ‘ignore_sticky_posts’ => 1 ); $query = new WP_Query( $args ); $ids_by_category = array(); while ($query->have_posts()) { $query->the_post(); $post_categories = wp_get_post_categories(get_the_ID()); foreach($post_categories as $c){ $cat = get_category($c); $ids_by_category[$cat->slug][] = get_the_ID(); } } // sort by key ksort($ids_by_category); … Read more

Retrieve data from wordpress db via input and put those result in dropdown

In the below code when you press button with the id findschoolname ajax will run. you can change the click event with on change of text box. the below script run ajax. <div class=”col-xs-4″> <div class=”zipcode”>Zip Codes <input type=”text” class=”form-control postcode” name=”postalCode” /> <input type=”button” id=”findschoolname”> </div> <div id=”replacedropwdown”> </div> </div> <script type=”text/javascript”> jQuery(document).ready(function(){ jQuery(“#findschoolname”).click(function(){ … Read more

var_dump of WP_Query object is not empty, while .have_posts() return false

The WP_Query::have_posts takes into consideration just the current_post and post_count properties of the object ( see the Code Reference for more details ). And those are, in deed, empty in your var_dump: [“posts”]=> array(0) { } [“post_count”]=> int(0) [“current_post”]=> int(-1) So perhaps the query args are not correct and you are attempting to query something … Read more

WPQuery calling specific posts problem

If you don’t specify the order and orderby arguments with your query, the results will be ordered ascending by date, no matter what order you put the pages in with post__in. If you have an order in mind that isn’t covered by one of the regular orderby arguments, you’ll have to define a metavalue on … Read more

How to get more data of a post by wp_query

WordPress has many built in functions that allow you to get whatever data you have added to your posts, whether it standard or custom. Example below: if ($query->have_posts()) { while ($query->have_posts()) { $posts = $query->get_posts(); $array[‘title’] = get_the_title(); $array[‘permalink’] = get_the_permalink(); $array[‘content’] = get_the_content(); $array[‘post_date’] = get_the_date(); if (has_post_thumbnail()) { $array[‘feat_image_url’] = wp_get_attachment_url(get_post_thumbnail_id()); } $array[‘custom_meta_1’] … Read more

Remove post type filter added by the plugin in the final query

The best course of action would be to prevent the plugin from doing something you don’t want. If for some reason this is not possible you can use the filter pre_get_posts to change the query before it is executed, like this: add_action( ‘pre_get_posts’, ‘wpse239465_force_post_type’, 9999); function wpse239465_force_post_type () { $query->set(‘post_type’, ‘mycustomepost’); } Note that this … Read more