wordpress-custom-fields-permalink-plugin icon indicating copy to clipboard operation
wordpress-custom-fields-permalink-plugin copied to clipboard

Using plugin break nested pages

Open athlan opened this issue 6 years ago • 6 comments

Followup from issue https://github.com/athlan/acf-permalink/issues/12 created by @SebKay.

Hi,

This plugin works perfectly with the custom fields for posts and custom post types, however, there's what seems to be a bug where nested pages go to a 404 when this plugin is active.

Any ideas why this might be?

athlan avatar Nov 21 '18 19:11 athlan

@SebKay I've recreated an issue in automated tests: https://github.com/athlan/wordpress-custom-fields-permalink-plugin/pull/42

Will investigate it.

athlan avatar Nov 21 '18 20:11 athlan

The first spot of investigation is that in case of permalink rule /%field_custom_field_params%/%postname%/ plugin cannot distinguish real attempt to query post with particular meta field value or nested page.

Debug: (disabled plugin)

array (size=8)
  'WORDPRESS_CUSTOM_FIELDS_PERMALINK_PLUGIN_VERSION' => null
  'extra_query_vars' => 
    array (size=0)
      empty
  'query_vars' => 
    array (size=2)
      'page' => string '' (length=0)
      'pagename' => string 'parent-page-2/child-page' (length=24)
  'query_string' => string 'pagename=parent-page-2%2Fchild-page' (length=35)
  'request' => string 'parent-page-2/child-page' (length=24)
  'matched_rule' => string '(.?.+?)(?:/([0-9]+))?/?$' (length=24)
  'matched_query' => string 'pagename=parent-page-2%2Fchild-page&page=' (length=41)
  'did_permalink' => boolean true

vs (enabled plugin)

array (size=8)
  'WORDPRESS_CUSTOM_FIELDS_PERMALINK_PLUGIN_VERSION' => string '1.5.0' (length=5)
  'extra_query_vars' => 
    array (size=0)
      empty
  'query_vars' => 
    array (size=3)
      'page' => string '' (length=0)
      'name' => string 'child-page' (length=10)
      'custom_field_params' => 
        array (size=1)
          'custom1' => string 'parent-page-2' (length=13)
  'query_string' => string 'name=child-page&' (length=16)
  'request' => string 'parent-page-2/child-page' (length=24)
  'matched_rule' => string '([^/]+)/([^/]+)(?:/([0-9]+))?/?$' (length=32)
  'matched_query' => string 'custom_field_params%5Bcustom1%5D=parent-page-2&name=child-page&page=' (length=68)
  'did_permalink' => boolean true

athlan avatar Nov 23 '18 17:11 athlan

Well, I have some workaround (link https://github.com/athlan/wordpress-custom-fields-permalink-plugin/pull/42, see WP_Request_Processor_Rewrite_Chain), little bit hacky, because if some rewrite rules raises 404 (WP only considers first rule) then second round is ran and seems to work.

However I cannot prove that by automated tests.

@SebKay Please confirm if you cannot put pots or pages under another URL (for example 1. setting up different permalink for posts, or 2. using custom post type with prefixed url).

athlan avatar Nov 23 '18 22:11 athlan

@SebKay Please confirm if you cannot put pots or pages under another URL (for example 1. setting up different permalink for posts, or 2. using custom post type with prefixed url).

The posts and custom post types are working fine, whether they have a custom field prefix or not. It's only becoming an issue when pages are nested within each other.

SebKay avatar Nov 26 '18 09:11 SebKay

What about putting posts into subpath like having permalink structure like /some_subpath/%field_ph_post_format%/%postname%/?

It could be simple workaround for now.

athlan avatar Nov 26 '18 10:11 athlan

I will give this a try and report back!

SebKay avatar Nov 27 '18 08:11 SebKay