When something doesn't work on a WordPress website (and when it's not a php error), what should be the protocol to properly identify the origin of an issue or an unexpected behavior ? How to proceed exactly : i mean, is there a very logical step by step process that i should follow ?

Here is the situation i'm facing, to illustrate my question : in a local environment, with the last version of WordPress, with Polylang ACF and ACF Post-2-Post plugins activated, I try to create a bidirectional relationship between two posts (one is a about an author, the other is about a book, and i use ACF Post-2-Post to display a link on each page in direction to the other), and it works perfectly when i use it on a standard template like Twenty Twenty or Twenty Seventeen : it displays a link on the book post targeting the author post, and it displays a link on the author post targeting the book post.

The issue I'm facing is : when i use my very and basic template everything is working except one part of the relationship : the link on the author post targeting the book post is still present, but not the one on the book post.

What should i check to be sure to identify the origin of my issue ?

EDIT : finally, i've found out the issue i'm facing was caused by a snippet of code I use in my functions.php in order to exclude from the homepage few posts belonging to some categories:

function exclude_category_home( $query ) {
  if ( $query->is_home ) {
    $query->set( 'cat', '-44, -46');
  return $query;
add_filter( 'pre_get_posts', 'exclude_category_home' );

But I still dont understand why I have this issue and how to understand or analyze the problem.

  • If it works fine in a standard theme then I'd guess something's wrong with your book post template. I'd try and work out what mechanism post-2-post is using to render the link in Twenty Seventeen, check that's in place in your template, check that all the state is still loading correctly (e.g. dump it out with error_log(print_r(..., true))) and generally just add trace until you can see what's different between the two. – Rup Jan 6 '20 at 12:40
  • (There are also ways to set up WordPress in an environment you can set breakpoints in and step through but I've never tried those myself.) – Rup Jan 6 '20 at 12:41
  • Ok, I will explore those two leads ! – PhpDoe Jan 6 '20 at 13:22
  • @Rup : OK, just to keep you updated, i've found out that the cause of the issue (i've edited my question), even if i still dont understand why it is causing this issue. – PhpDoe Jan 6 '20 at 14:59
  • Great! Maybe you need to test $query->is_main_query() too? And/or check if there's already a cat list set and append to it rather than just overwriting it. – Rup Jan 6 '20 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.