Here is my solution without changing the post object:
Add a new rewrite rule, look this up if you need to:
add_rewrite_rule("^news/?$", "index.php?post_type=post&category_name=news", "top");
Adding category_name=news triggers the archive.php file to be used. Yes, you need to add the category news to every post but this is no big deal if you set news to the default category in writing settings.
Change post archive link:
function my_post_archive_link( $link, $post_type ) {
if ( $post_type == 'post' ) {
$link = site_url( '/news/' );
}
return $link;
}
add_filter( 'post_type_archive_link', 'my_post_archive_link', 10, 2 );
This is the best solution I have come up with- without having to hack the post object or create a new custom post type just for news.
Related Posts:
- permalinks with get variables
- WordPress plugin how to run function when button is clicked
- Use an empty page to build custom plugin output
- Creating a path in a plugin to call a function
- URL rewriting must be activated manually for my plugin
- 404 errors after plugin options update and category base change
- Why doesn’t flush_rewrite_rules run on plugin activation?
- Auto save permalink setting page with the plugin activation
- Help With Rewrite_Rules For a Custom Plug-In
- Append varible to url or set session
- How can I turn a custom wordpress page into a product page?
- rewrite URL based on selected taxonomy for post page
- Problem with dinamic add_rewrite_rule()
- Remove custom post type slug from URL and add taxonomy Slug
- add_rewrite_rule behaving strangely
- custom permalink’s rewrite rule for page id
- Show content without a post
- How to get post image root URL?
- How to create new content type and flushes rewrite rules without visiting the permalinks page?
- Forward an old url rewrite scheme to a new one?
- Changing permalink structure breaks link to .php file which generates files dynamically
- wp_insert_post generated mixed permalinks
- How to link to custom “archive like” page with custom permalink rules “dynamically”
- Add variables from rewrite rules to query var
- Home page is not loading, where in other pages are displaying on the site
- Get the current post/page URL with plain permalinks
- Adding body class in author page for custom role
- Author Meta in Author URL Link
- WordPress plugin how to run function when button is clicked
- Get (eventual) permalink from post within Edit Post in Admin panel
- WordPress permalink setting
- Get URL of Post You Are Editing
- How to use permalink query to go to specific tabs in posts
- Custom rewrite, url path with parameters to a page
- Change the_title() of a page dynamically
- Adding more options to the instance of an image. (Attachment Display Settings)
- What is wrong with using add_option with Multisite instead of add_blog_option in a plugin
- Trouble with Transient API when W3TC is activated [closed]
- Using wp_filesystem in Plugins
- WordPress REST API call generates nonce twice on every call
- Filters ‘request’ and ‘parse_query’ not firing in sites.php nor link-manager.php
- How to trap “Publish” button to check for meta box validation?
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- $wp_filesystem returns NULL. What are the dependencies?
- wp_mail not recognizing cc and bcc headers
- Plugin Loading Scripts and Styles on Every Page – Even when not being used
- wp_remote_get keeps timing out
- Extending WP_List_Table seems getting wrong with $this->get_columns() – what’s wrong?
- Finding posts containing matching array elements in a meta field usign WP_Query
- Should shorcodes in i18n plugins be translated and if so, how?
- how to use hook deleted_user into custom function to delete user from custom table
- Show User’s Current Time
- Single sanitization callback for multiple fields
- How to filter users list on user_status field with get_users()
- Where did the ability to edit a plugin go?
- How to add custom fields to the all users page
- Can Page Templates be Applied to Archive and Post Templates?
- Adding custom end points, No error line
- Custom login doesn’t work properly
- automatic change post date when post is 30 days old
- Translate slug in WPMU with PO files
- Allow users to add / remove settings in plugin
- Plugin – Make sure jquery is loaded in my settings page plus my JS file
- wp_editor add media button not working
- Plugin Development – Class Constructor Not Firing wp_enqueue_style action hook
- Alternative functions for mysql_free_result and mysql_ping in wordpress functions
- Getting a WordPress Debug Strategy
- Add function after the_content
- Best way to include and use Zoho SDK in a wordpress plugin
- How to change WooCommerce loop product title HTML output in single product page and archive page
- How remove trashed WooCommerce orders from wc_get_orders() result?
- How do I get variables from my plugin’s settings page?
- Unexpected T_FUNCTION
- How to avoid conflicts with db.php / $wpdb and other plugins that decide to use them?
- Plugin can’t be activated [closed]
- How To Protect Plugin Display From Being Affected By Theme’s CSS
- Is there an action_filter hook to add content before the post title?
- CSS not being applied using wp_enqueue_style
- Add quick edit functionnality to plugin table
- Hide / show settings field based on other field’s value
- using wordpress acf shortcods in tables goes outside the table
- $_SESSION inside php function executed by AJAX
- Two same AJAX calls – one is working, other doesn’t
- remove different admin menu for specific users
- add pagination to wp_remote_get
- Adding and handling custom settings tab to fusion element
- Shortcode from a plugin not working
- How to get option values without requiring wp-load?
- Problem with baseurl and interaction with plugin
- Why setcookie function redirecting to home page in wordpress?
- Should all roles be allowed CRUD operation on the database?
- Downloading Generated XML File
- Can’t get query string in ajax call
- Conditional query tags do not work before the query is run. Before then, they always return false
- Send Webhook when post-status is publish or trash
- add category id to option name when adding an option on edit_category
- esc_url, esc_url_raw or sanitize_url?
- React Plugin Settings Page Localization
- Is it within WordPress guidelines to update another plugin’s database fields from my own plugin? [closed]
- Block Development: hamburger module throwing error in save function