Questions tagged [wp-reset-postdata]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
1 answer
503 views

How to stop wordpress from redirecting from the post's old slug after changing title and slug?

After changing a post's title/slug from mysite.com/name to mysite.com/new-name, the old slug mysite.com/name is now redirecting to the new one mysite.com/new-name, and I don't want that to happen. I ...
cashrunner's user avatar
-1 votes
1 answer
144 views

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' ) ) )...
Happy Arif's user avatar
2 votes
1 answer
784 views

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 ...
SoloCrowd's user avatar
0 votes
1 answer
189 views

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' => ...
Piotr Orczyk's user avatar
0 votes
0 answers
126 views

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) ...
Boyzen's user avatar
  • 23
5 votes
1 answer
7k views

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

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 ...
jonnyK's user avatar
  • 91
0 votes
3 answers
2k views

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' => ...
Steve Rodgers's user avatar
0 votes
1 answer
113 views

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 ...
Sahil Shukla's user avatar
0 votes
1 answer
221 views

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 ...
Rafiq's user avatar
  • 90
4 votes
1 answer
1k views

Why should i use wp_reset_postdata()?

I am not able to understand the use of wp_reset_postdata. what could go wrong if i am not using it? https://codex.wordpress.org/Function_Reference/wp_reset_postdata Here in documentation what is ...
user avatar
0 votes
2 answers
829 views

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 ...
Jimbo's user avatar
  • 151
0 votes
0 answers
901 views

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 = ...
Toni Michel Caubet's user avatar
0 votes
2 answers
525 views

WP CLI can't delete plugin related table

I have installed a plugin following wp plugin install ... CLI command and then activate through CLI command its working properly. But problem is that when I deactivate then delete the plugin the table ...
Nazmus Shakib's user avatar
1 vote
1 answer
714 views

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 ...
galingong's user avatar
  • 180
4 votes
1 answer
3k views

When should you use wp_reset_postdata vs wp_reset_query?

Seems like half the tutorials in the Codex use wp_reset_postdata() and half use wp_reset_query(). What's the deal? Maybe Use both of them? What about rewind_posts()? I am asking for an answer based on ...
Narek Zakarian's user avatar
5 votes
3 answers
4k views

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 ...
user9447's user avatar
  • 1,772
0 votes
1 answer
61 views

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="&...
glvr's user avatar
  • 881
0 votes
1 answer
339 views

Populate metabox dropdown with post title from another Custom Post Type (issues with wp_reset / global $post)

I have a custom post type, and in there I have a metabox with a dropdown. The dropdown is populated with the titles of posts from another custom post type. My metabox system works. I tried ...
Quin's user avatar
  • 21
0 votes
1 answer
30 views

How to trigger error when not using wp_reset_postdata();? Why use it if the loop works without it?

I have two loops in my code, why do I need to use wp_reset_postdata(); after each if it doesnt make any difference? The definition: After looping through a separate query, this function restores the $...
Johnthomas's user avatar
0 votes
1 answer
502 views

Calling a function with WP_Query only ever brings the first result

So I made a simple php script to display the top 3 posts in a category as a list. Pretty simple. Thing is I'm going to be using it quite a bit so I thought I'd be cleaver and write it out as a ...
Robert Porter's user avatar
1 vote
0 answers
400 views

reset to main loop doesnt work

I open the administration page for my custom post type. So the url is: wp-admin/post.php?post=39&action=edit When I do the following Code, the output is of course 39: <?php global $post; ...
Carsten Schmitt's user avatar
1 vote
2 answers
630 views

wp_reset_postdata does not work for category page

I have a category template which displays some posts and some content generated by a plugin template, which uses the_permalink() to refer to the current url. The category template looks like this (...
Manolo's user avatar
  • 533
1 vote
0 answers
1k views

wp_reset_postdata() and wp_reset_query() inside shortcode are not working to reset original page query

I'm implementing a form for a frontend post with a shortcode. The form is processed in the same function, reloading the page: function adicionar_ninhada(){ $user_id = get_current_user_id(); if (isset(...
Ricardo Gonçalves's user avatar
7 votes
1 answer
1k views

How does reset_postdata restore the post of the main query loop?

How does reset_postdata works? The docs say: restore the global $post variable of the main query loop after a secondary query loop using new WP_Query But in the class, it takes the "current" ...
Paul's user avatar
  • 319
0 votes
1 answer
102 views

Optimizing the blog loop

I've got such post loop: <?php global $post; $post = $post_object; setup_postdata( $post ); $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts(array( 'post_type' ...
Paweł Skaba's user avatar
0 votes
1 answer
250 views

numberposts not responding to wp_reset_postdata()

I am working on a loop where I want the content (from 2 separate categories) to be displayed like this: 1 large format post, 1 random product, 2 small format posts, 1 feature post ...repeat. In order ...
GBin's user avatar
  • 11
0 votes
0 answers
85 views

Correct Way To Run Multiple Queries Sharing Some Base Data

I need to run three queries on the same page. The 'core' query is the same all three times - selecting posts in a particular taxonomy. I then need to run three queries on that subset looking for ...
Kevin4fm's user avatar
0 votes
1 answer
470 views

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 ...
bashleigh's user avatar
  • 376
1 vote
1 answer
50 views

Is resetting post data necessary with custom WP_CLI commands?

Is it strictly necessary to call wp_reset_postdata(); in a WP CLI command? I am doing it out of habit but just wondered if the $post object needed to be reset.
Welcher's user avatar
  • 3,588
0 votes
2 answers
1k views

Set post number to single posts

I have a function that I am using to number posts in a category. It is in my function.php and looks like this: function get_episode_number($postID){ $options = get_option('theme-opts'); $opts_cat = ...
kath's user avatar
  • 601
0 votes
2 answers
15k views

Custom WP_Query not working correctly

OK, So I have created a custom WP_Query that gets the post_type post and outputs it as a styled list. It works well and outputs the styled list but then underneath it displays all the posts again but ...
Chris's user avatar
  • 399
0 votes
2 answers
3k views

Sort order in get_posts [closed]

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 ...
tadywankenobi's user avatar
65 votes
1 answer
89k views

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....
bestprogrammerintheworld's user avatar
-1 votes
1 answer
1k views

Resetting a Query using wp_reset_query() or wp_reset_postdata() does not work

I am using ACF as related posts. I have the following code. <?php $post_objects = get_field('repeater_related_items'); if( $post_objects ): ?> <ul> <?php foreach( $post_objects ...
Hussain Ansari's user avatar
2 votes
1 answer
4k views

Should 'setup_postdata()' be reset with 'wp_reset_postdata()'?

Starting with an example makes more sense, so here's an example function: function seo_meta_tags() { global $post; if( is_singular() ) { setup_postdata( $post ); $...
its_me's user avatar
  • 4,511
0 votes
1 answer
285 views

Optimizing multiple WP_querys into one call?

I have finished building my website and noticed due to the structure it takes 3 seconds to load the data due to each WP_query bouncing between different post types. I was wondering if I put these into ...
Serpream's user avatar
1 vote
2 answers
4k views

Why is wp_reset_postdata() restarting the loop from the first post?

I've used the second-last example showed here: https://github.com/scribu/wp-posts-to-posts/wiki/each_connected The only difference is that I've put the_title after echoing the connected posts. So my ...
Marco Panichi's user avatar
11 votes
1 answer
11k views

Is it necessary to reset the query after using get_posts()?

Is it necessary to reset the query after using get_posts() ? I have been looking at this page and I don't see any reference to get_posts() ... I can't make it out for sure from this page either. I ...
byronyasgur's user avatar
  • 3,032
1 vote
1 answer
1k views

Is there any need to use both wp_reset_postdata and wp_reset_query together?

Is there any need to use both wp_reset_postdata() and wp_reset_query() together? Is it a case that I would pick one of the two functions; is there any point in doing this after a query : ...
byronyasgur's user avatar
  • 3,032
0 votes
1 answer
764 views

How to reset post data properly

I have this piece of code that I am calling within the loop to get image metadata ( title/caption and description ). It works fine but it only works for the first post in the loop. So I assume it ...
byronyasgur's user avatar
  • 3,032