Why not showing all post by default in my jquery filter

Hello Expert Developer, Can you please take a look on it, What i did messed up? function mysite_filter_function(){ //groups checkboxes if( $groups = get_terms( array( 'taxonomy' => 'category' ) ) ) : $groups_terms = array(); foreach( $groups as $group ) { if( isset( $_POST['group_' . $group->term_id ] ) && $_POST['group_' . $group->term_id] == 'on' ) $groups_terms[] = $group->slug; } endif; $tax_query = array( 'relation' => 'AND' ); if ( ! empty( $groups_terms ) ) { $tax_query[] = array( 'taxonomy' => …
Category: Web

Displaying requested data from a the database in wordpress

I added my data base on my wordpress server. Now I want people on my page to have the option to enter a LionID and then be given the data of that lion. I would like to display the data in a way as shown in the 2nd photo. Furthermore, this dataset also has a URL link of the image of each lion. I would also like to display these next to the values ​​given. Hopefully this is possible. Thanks …
Category: Web

Sort order in get_posts

I've created a custom template for a client. This is going to be a multilingual site setup on a Multisite install. As you can see under each category letter, the posts start out in alphabetical order but "M" and "O" are all out of whack. If you click through onto those categories, using the alphabet bar at the top, those posts are in alphabetical order. Both pages are using the same code, so I've no idea what I'm doing wrong. …
Category: Web

Trouble with wp_reset_postdata() in Admin Panel

I'm hooking into 'edit_form_after_editor' add_action('edit_form_after_editor', 'make_the_button_to_generate_a_report_number'); function make_the_button_to_generate_a_report_number($post) { Check that I am dealing with a custom post type of 'publications' if ($post->post_type != 'publications') return; Create a number of arguments that I then run in a WP_Query $new_query = new WP_Query($report_number_args); use that data to do stuff... Then I want to reset $post back to how it was, so I run wp_reset_postdata(); But $post stays on the last item I had received from my new WP_Query(). What am I …
Category: Web

3 posts from each existing category on one page

The following is not working... <?php $categories = get_categories( array( 'orderby' => 'name', 'parent' => 0 ) ); foreach($categories as $category): $args = array( 'cat' => $category->name, 'posts_per_page' => 3,); $category_posts = new WP_Query( $args ); if( $category_posts->have_posts() ): ?> <h2><?php echo $category->name; ?></h2> <div class="row"> <?php while( $category_posts->have_posts() ): $category_posts->the_post(); ?> <div class="blog-post-tile" style="background-image: url(<?php echo get_the_post_thumbnail_url(get_the_ID(), 'full');?>)"> <h3 class="blog-post-tile__title"> <?php the_title(); ?> </h3> </div> <?php endwhile; ?> </div> <?php endif; wp_reset_postdata(); wp_reset_query(); endforeach; My goal is to display …
Category: Web

wp_reset_postdata not working

i have this query add_action('edit_form_after_title', 'get_books'); function get_books($main_post){ global $post; $list = ''; // print the current post (everything is still fine here) print_r($post); $args = array( 'posts_per_page' => '20', 'post_type' => array('books') ); $my_query = new WP_Query($args); if ($my_query->have_posts()) { $list .= '<select name="books_list">'; while ($my_query->have_posts()) { $my_query->the_post(); // my code $list .= '<option value="'.get_the_ID().'">'.get_the_title().'</option>'; } $list .= '</select>'; wp_reset_postdata(); } // i try another methods but still same problem. wp_reset_postdata(); $my_query->reset_postdata(); wp_reset_query(); // here print the last post …
Category: Web

ACF Repeater loops and resets - where is the reset_rows() documentation?

I love ACF, its great for developers and it seems to have so much support. BUT... Why is reset_rows() not in the documentation? I created a function that can delete repeater rows at different times in the code. I was using the rows loop each time expecting it to start at index 0 (or 1 in acf's crazy way). But each loop started where the previous one left off. This gave me grief for quite a while. I have only …
Category: Web

WP_Query not resetting after wp_reset_postdata

I have this custom query: if (isset($_COOKIE['myCookie']) && $_COOKIE['myCookie'] == $f_r) { $args = array( 'posts_per_page' => 4, 'nopaging' => false, 'order' => 'ASC', 'orderby' => 'rand', 'tax_query' => array( array( 'taxonomy' => 'Count', 'field' => 'slug', 'terms' => $f_r, ) ) ); $query = new WP_Query( $args ); if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); <a href="<?php the_field('the_link'); ?> "> <img src="<?php echo the_field('the_img'); ?>" /> </a> } else { echo 'Oops! Something went wrong!'; …
Category: Web

Unable to reset post data in wordpress custom query

Edit - I already tried wp_reset_query() it doesn't work, the first loop executes as intended but the second loop just jumps to the else and I get not working I am using 2 custom WP_Query loops in one page, the first is to get posts from a certain category, and the second is just getting the posts by dates, here's the code <?php $args = array( 'post_type' => 'post', 'post_status' => 'any', 'category' => 3, 'posts_per_page' => 4); $query_var= new …
Category: Web

Can't reset the secondary query by wp_reset_postdata()

In custom post meta I have executed a custom query to get custom meta but when I tried to return to the main $post query, its printing the secondary loop.Where is my custom query and I have reset it by wp_reset_postdata().But no result. $custom_fields = get_posts( array( 'post_type' => 'custom_field', 'posts_per_page' => -1, 'post_status' => 'publish', 'meta_key' => 'associate', 'meta_value' => 'form' ) ); foreach ($custom_fields as $post) { setup_postdata($post); var_dump(get_the_ID()); } wp_reset_postdata(); wp_reset_query();
Category: Web

wp_reset_postdata() or wp_reset_query() after a custom loop?

Reading some stuff about query_reset_postdata and query_reset_query makes me confused. For example: Is there any need to use both wp_reset_postdata and wp_reset_query together? http://www.poststat.us/properly-reset-wordpress-query/ Above states that you should only use query_reset_postdata() when using "separate queries". In example2 there's a comment: WP_Query( $args ) = wp_reset_postdata(); AND query_posts ( $args ) = wp_reset_query(); And really you should never use wp_reset_query because you shouldn't use query_posts!? In the WP Codex it states that you should use wp_reset_query() after a custom loop …
Category: Web

Admin Page Post Id wp_reset_postdata not working

Have 2 plugins which power some extra woocommerce custom options in WP. Both hook to plugins_loaded. The 1st plugin is not resetting to the original post data by the looks of things. One plugin is a sample drop down with the post metaboxes. The plugin queries the db using WP_Query to output a select options box. I run wp_reset_postdata() after. The second plugin is a different select box which is not pulling with the correct post id so the meta …
Category: Web

What's causing an infinite loop?

I have to use parent posts as categories. So I'm checking if current post has childs and show them or else show te content. I'm trying like this (in single-practice.php): <?php $has_children = false; $children = get_children( array( 'post_parent' => get_the_ID() ) ); wp_reset_postdata(); if ( ! empty($children) ) { $has_children = true; } if ($has_children) { $args = array( 'post_type' => 'practice', 'orderby' => 'menu_order', 'post_parent' => get_the_ID(), 'paged' => false ); $query = new WP_Query( $args ); /* …
Category: Web

Reset postdata to custom query in nested queries

I have a main query, in which I set up a new custom query to retrieve posts (think about 'related posts' or something like that). Than in each of those posts, I'm setting an other custom query, load data from a single post, then I should find a way to reset postdata to the first custom query. How can I do that? I tried wp_reset_postdata(), but that resets to main query. A simplified code would look thus: while ( have_posts() …
Category: Web

get_post_fields as an excerpt

I have a strange question, I have built my site and my loop etc. But on my sidebar I want to add a sort of random post display, but I don't want the entire post to display, I've had some difficulties achieving this so if you have any alternative methods you wish to share, please let me know :) What I want to achieve at the moment is shorten the content shown, I know you can do this with excerpt() …
Category: Web

Where should you reset postdata?

I've searched for this in the Q&A but I was unable to find it. When I read answers throughout the site I see wp_reset_postdata() placed in multiple areas with the have_posts() conditional and outside the conditional all together. When I read the documentation on wp_reset_postdata() all it states is: After looping through a separate query, this function restores the $post global to the current post in the main query. with a snippet of: <?php // example args $args = array( …
Category: Web

Do I need to reset the loop in this code?

I use the code below, added to a template, to display random posts. <ul> <?php $posts = get_posts('orderby=rand&numberposts=5'); foreach($posts as $post) { ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li> <?php } ?> </ul> Do I need to reset, presumably by changing <?php } ?> to <?php } wp_reset_postdata(); ?> And does the need to reset depend on whether this code-block is before or after other loops/queries in the template?
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.