使用WP Remote Post及WP内发帖均遇404错误,求问题排查
Hey there, let's break down why you're hitting this 404 error both with WP Remote Post and when publishing directly in WordPress—super frustrating, I know. Here are the most common culprits and actionable fixes to try:
1. Permalink Structure Glitches (Most Likely Fix)
WordPress relies on rewrite rules to map pretty permalinks to actual content. If these rules get corrupted, you'll see 404s across the board.
- Quick fix: Head to your WordPress dashboard → Settings → Permalinks. Switch to a different structure (like "Plain") and save changes. Then switch back to your preferred structure (e.g., "Post name") and save again. This forces WordPress to regenerate the rewrite rules.
- Server-specific checks:
- For Apache: Ensure your root directory has a
.htaccessfile with the correct WordPress rewrite rules. It should look like this:
Also confirm the# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPressmod_rewritemodule is enabled on your server. - For Nginx: Verify your server block includes the necessary rewrite rule to pass requests to WordPress:
location / { try_files $uri $uri/ /index.php?$args; }
- For Apache: Ensure your root directory has a
2. Custom Post Type (CPT) Configuration Errors
If you're publishing to a custom post type, misconfigured rewrite settings here can trigger 404s.
- Check your
register_post_type()code: Ensure therewriteparameter is set correctly (no duplicate slugs, andwith_frontis adjusted to your needs). Example:register_post_type('your_cpt', array( 'rewrite' => array('slug' => 'your-cpt-slug', 'with_front' => false), // other CPT settings... )); - After adjusting the code, don't forget to regenerate permalinks (follow the step in section 1) to update the rewrite rules for your CPT.
3. Plugin or Theme Conflicts
Third-party code can often interfere with WordPress's publishing flow or rewrite rules.
- Test plugins: Disable all plugins, then try publishing again. If the 404 goes away, re-enable plugins one by one, testing after each, to find the culprit. Common offenders include security plugins, SEO tools, or custom post type managers.
- Test theme: If disabling plugins doesn't help, switch to a default WordPress theme (like Twenty Twenty-Four) and test publishing. This rules out issues with your active theme's custom code.
4. WP Remote Post Specific Checks
Even though the backend is also failing, double-check your API setup to eliminate any overlap:
- Confirm your API endpoint is correct: For default posts, it should be
https://your-domain.com/wp-json/wp/v2/posts(replaceyour-domain.comwith your actual site URL). - Verify authentication: If using Basic Auth, ensure your username/password are correct. For Application Passwords (the recommended method for WP REST API), confirm the generated password is valid and the associated user has publish permissions.
- Check server firewalls: Some hosting providers or security tools block API requests—review your server logs to see if requests are being intercepted.
5. Server-Side Issues
If none of the above work, dig into server-level problems:
- File permissions: Ensure WordPress directories (like
wp-content) and files have correct permissions (typically 755 for directories, 644 for files). Avoid overly permissive settings (like 777) which pose security risks. - Server logs: Check your web server's error logs (Apache:
error.log, Nginx:error.log) for specific details about the 404. Logs might reveal missing files, permission errors, or rewrite rule failures that aren't visible in WordPress.
Start with the permalink fix first—it's the quickest and most likely solution. If you're still stuck, share any custom code (like CPT registration) or server log snippets, and we can troubleshoot further.
内容的提问来源于stack exchange,提问作者Debu

