Add_rewrite_endpoint doesn’t work with post name permalink structure

I would avoid using add_rewrite_endpoint() directly to register account page endpoints in WooCommerce. WooCommerce has a filter that you can use that make sure everything else works properly, like the endpoint title filter and calls to is_wc_endpoint_url(). So add the endpoint with the woocommerce_get_query_vars filter: add_filter( ‘woocommerce_get_query_vars’, function( $query_vars ) { $query_vars[‘conversations’] = ‘conversations’; return … Read more

Permalinks on Windows IIS not working and web.config breaks site – does wordpress not support windows server now, if so how?

Download IIS Rewrite from https://www.iis.net/downloads/microsoft/url-rewrite. Install and restart IIS Then modify the web.config Edit web.config, add the rewrite code. <?xml version=”1.0″ encoding=”UTF-8″?> <configuration> <system.webServer> <defaultDocument> <files> <add value=”index.php” /> </files> </defaultDocument> <rewrite> <rules> <rule name=”Main Rule” stopProcessing=”true”> <match url=”.*” /> <conditions logicalGrouping=”MatchAll”> <add input=”{REQUEST_FILENAME}” matchType=”IsFile” negate=”true” /> <add input=”{REQUEST_FILENAME}” matchType=”IsDirectory” negate=”true” /> </conditions> <action type=”Rewrite” … Read more

How to rewrite the beginning and end of the permalink structure in a custom post type?

I recently wrote an answer to a similar question, so be sure to check it out because you can just use the same code, except you’d use the post type dvposts and not ex_article, and use the structure d/%dvposts%/%post_id%. But the trick there is quite simple: When you call register_post_type() with rewriting enabled, WordPress always … Read more

Set parent for custom post type archive rewrite url

First, you need to register the %office% rewrite tag: // First, add the rewrite tag. add_rewrite_tag( ‘%office%’, ‘([^/]+)’, ‘post_type=office_members&office_name=” ); // Then call add_permastruct(). add_permastruct( “office_members’, … ); Then, add the custom office_name arg to the public query vars so that WordPress reads/parses it from the URL: add_filter( ‘query_vars’, function ( $vars ) { $vars[] … Read more

how to get a list of all top level pages

$query_args = array( ‘post_type’ => ‘page’, ‘post_status’ => ‘publish’, ‘parent’ => 0, ); $pages = get_pages( $query_args ); Function get_pages() accepts parameter with parent. Keeping it 0 (zero) will give us first level pages. In the example $pages will contain the first level pages. Use loop for $pages and you can use it in option … Read more

How to add a sub directory to WordPress single posts without affecting other post types?

If we look at the register_post_type documentation, in the rewrite option, there is a sub-option that controls this: ‘with_front’ => bool Should the permalink structure be prepended with the front base. (example: if your permalink structure is /blog/, then your links will be: false->/news/, true->/blog/news/). Defaults to true So something like this: … ‘rewrite’ => … Read more