Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

The tag has no usage guidance.

0
votes
1answer
12 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 ...
3
votes
1answer
255 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 ...
-1
votes
1answer
92 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 ...
0
votes
0answers
96 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 = ...
0
votes
2answers
28 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 ...
0
votes
1answer
112 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 ...
1
vote
1answer
428 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 ...
5
votes
3answers
533 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 ...
0
votes
1answer
19 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="&...
0
votes
1answer
78 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 ...
0
votes
1answer
23 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 $...
0
votes
1answer
48 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 ...
1
vote
0answers
282 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; ...
1
vote
2answers
254 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 (...
1
vote
0answers
463 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(...
7
votes
1answer
352 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" ...
0
votes
0answers
34 views

Use two categories and remove for first data

So I find id for two post categories, and now I'm trying to write php code in content-single.php in acesspress lite. This is that I obtained: <article id="post-<?php the_category_ID(7); ?>" &...
0
votes
1answer
81 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' ...
0
votes
1answer
128 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 ...
0
votes
0answers
77 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 ...
0
votes
1answer
206 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 ...
1
vote
1answer
41 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.
0
votes
2answers
110 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 = ...
0
votes
2answers
7k 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 ...
0
votes
2answers
622 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 ...
37
votes
1answer
35k 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....
-1
votes
1answer
847 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 ...
2
votes
1answer
1k 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 ); $...
0
votes
1answer
185 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 ...
1
vote
2answers
3k 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 ...
5
votes
1answer
5k 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 ...
1
vote
1answer
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 : ...
0
votes
1answer
575 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 ...