• Resolved spinhead

    (@spinhead)


    Consistent issue with wp cli installs: my script includes one or both of these:

    wp option update permalink_structure ‘/%postname%/’;

    wp rewrite structure ‘/%postname%’;

    yet links in the menu fail. No errors are returned.

    In the admin dashboard, the setting shows ‘Custom Structure’ with /%postname%/ in the #permalink_structure input field. I change it to the ‘Post name’ option, which has no visible change on the page other than to move the radio button selection, but then, menu links work as expected.

    The URLs involved never change, they simply go from 404 to working.

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • I tested this out using the provided wp commands. I wasn’t able to reproduce the problem with wp option update permalink_structure '/%postname%/', however I was able to with wp rewrite structure '/%postname%'. After running it, the setting shows up in ‘Custom Structure’ as you’ve described.

    In the latter command, it appears there is a missing trailing slash. If I update the line to be as follows, then after running the command, the option in the admin dashboard appears to be correctly set to the ‘Post name’ option:

    wp rewrite structure '/%postname%/'

    In terms of the 404 issue after updating the urls, I wasn’t able to replicate this problem in my test environment. WordPress should usually handle this gracefully as the user_trailingslashit function is used in a lot of places to check whether or not the current permalink rules involve a trailing slash when outputting urls. If you’re still getting 404s, the next steps might be to either double-check your web server configuration, or whether the menu in question is using custom links for the pages.

    Thread Starter spinhead

    (@spinhead)

    Apologies for leaving this out: the trailing slash isn’t the issue; I have used both commands with and without, but the issue absolutely occurs when the trailing slash is used.

    As I said in the original post, the URLs involved never change, they simply go from 404 to working. As in, the URLs are identical in every way, including trailing slashes.

    Thanks for the extra context! It sounds like something isn’t working correctly with the rewrite rules when updating via the CLI. Another thing to check is that the WP-CLI config has been configured to use the mod_rewrite module, so that it can correctly regenerate a .htaccess file. There is a little more info linked at the top of the WP CLI page for the wp rewrite structure command here: https://developer.www.ads-software.com/cli/commands/rewrite/structure/

    There is also the --hard option that can be added to the wp rewrite structure line to perform a hard flush that updates the .htaccess rules as well as the rewrite rules in the database.

    Thread Starter spinhead

    (@spinhead)

    Bingo.

    Added the config.yml file and used the --hard option, and it’s perfect.

    Thanks muchly, @andrewserong

    Excellent, glad we could get to the bottom of it!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘setting permalinks with wp cli doesn’t take but works in admin screen’ is closed to new replies.