Plugin Contributor
Roch
(@rochesterj)
Hi!
Thanks for reaching out.
The page is password protected so we can’t check it.
What theme are you using? Usually when this happens it’s a theme or wp settings issue
Thanks!
Hi,
We are using the Newspack Theme. The password for the website is “ilovenews”.
https://crictoday-newspack-2.newspackstaging.com/match/india-vs-pakistan/
Kindly Suggest What to do in this Regard.
Thanks.
Plugin Contributor
Roch
(@rochesterj)
Hi there!
What happens when you briefly switch to a different theme such as Rookie or Twenty Seventeen?
Thanks!
Hi,
I have used Sportpress Plugin on “Twenty Nineteen” theme on another server. It is working correctly on it. I am giving you the link of the website in which I have used the sportpress plugin :
http://grehlakshmipageants.com/?sp_event=india-vs-pakistan
I think the problem is coming with the “Newspack Theme” which I am using currently.
Thanks.
Plugin Contributor
Roch
(@rochesterj)
Hi there!
Thanks for your reply.
Indeed, if it works fine on a default theme, then it’s likely to be an issue with your theme. The theme authors can help you, or you can use a different theme.
Thanks!
Hi, theme author (sort of) here :wave:
The plugin works fine over on this site using essentially the same theme so it’s strange that it doesn’t work for this one.
It does sometimes work, with enough flushing of permalinks. It’s almost as if something is preventing permalinks from saving.
I have a local setup where I have the Newspack theme + SportsPress with the content imported (using WXR) and the same settings and it works fine.
Any special insight you have on what might be going wrong and areas of investigation I can look into would be very much appreciated 🙂
For example, the first time I opened it today it worked fine. Here’s a screenshot: https://cloudup.com/cPXIM8oY5DX
The moment I refresh, it 404s.
Here’s the relevant section of $wp_rewrite
which looks fine:
["sp_event"]=>
array(8) {
["with_front"]=>
bool(true)
["ep_mask"]=>
int(1)
["paged"]=>
bool(true)
["feed"]=>
bool(false)
["forcomments"]=>
bool(false)
["walk_dirs"]=>
bool(true)
["endpoints"]=>
bool(true)
["struct"]=>
string(17) "/event/%sp_event%"
}
-
This reply was modified 2 years, 3 months ago by
Philip John.
I’ve found the cause. It’s this function in includes/class-sp-post-types.php
public function display_scheduled_events( $posts ) {
global $wp_query, $wpdb;
if ( is_single() && $wp_query->post_count == 0 && isset( $wp_query->query_vars['sp_event'] )) {
$posts = $wpdb->get_results( $wp_query->request );
}
return $posts;
}
Specifically this line:
$posts = $wpdb->get_results( $wp_query->request );
That has the effect of resetting the main query, breaking the loop and causing the Not Found. If I simply comment out that line, it works fine. I’ve been testing on a clone site with only SportsPress, SportsPress for Cricket and the default theme (Twenty Twenty-One) active. You can see it here (pwd ilovenews
)
-
This reply was modified 2 years, 3 months ago by
Philip John.
Plugin Contributor
Roch
(@rochesterj)
Hi @philipjohn
That’s amazing, thank you so much for coming here to help us.
Let me tag our dev team here so they can check it as well.
@savvasha what do you think about it?
Thanks!
Plugin Contributor
Savvas
(@savvasha)
Hi guys…
I dont think that this is the issue. The above query cannot reset The Loop. Unfortunately I am not able to reproduce it either locally or remotely, so we can only wait for other users with similar issue to jump in. Maybe that way we can define a pattern and solve it 😉
Thanks everyone!
Savvas
Hi Savvas,
It effectively resets the query because $wpdb->get_results( $wp_query->request );
re-runs the query.
In a vanilla install with the default theme and just SportsPress you can dump the value of the global $post
variable within hooks like pre_get_posts
and parse_query
which will show you how the $post
variable is changing, causing the issue.
Remove that line and you’ll see that the main query is maintained and the $post
is not changed.
As a general rule, $wp_query
should not be messed with in this way as it can cause these kinds of unexpected consequences.