Tag Info

New answers tagged

0

I just completed something like this (with great help from folks on this site). First, you need to add the rewrite endpoint to your functions: function wpa_read_endpoint(){ add_rewrite_endpoint( 'sub-url', EP_PERMALINK); } add_action( 'init', 'wpa_read_endpoint' ); Make sure to then go to the permalinks section of admin and save to refresh permalink ...


0

I found the solution. function add_rewrite_rules($rules) { $newrules = array('cpt-slug/([^/]+)/([^/]+)/?$' => 'index.php?name=$matches[1]&post_type=cpt_name&member_view=$matches[2]'); $rules = $newrules + $rules; return $rules; } You just need to change 'p' to 'name'


0

I'd say what you need to look deeper into is the Rewrite API and Endpoints, for starters see: Make WordPress: Rewrite endpoints API Codex: Rewrite API Codex: Rewrite API/add rewrite endpoint Additionally use the the search on here, because there are already similar Q&A's, which will definitely help you. Last note, doing such things manually ...


0

I don't understand what you want to do. Every taxonomy is independent and the terms can't be shared between them. The only way I know to do a search with 2 parameters: taxonomy A term and taxonomy B term, and pass it to a WP Query along with the custom post type.


0

I think you have to set the slug value to an empty string like '', deleting item. I think that @kaiser think that item is a generic string for the posts, and he suggest to not prepend that string to your custom post type permalink. That's a good idea. But item is the slug for the CPT, so that's why is not working


0

Heres another solution <?php //Configruations $endpoints = array( '/' => array( 'homepage', '404 Not found' ), 'cats' => array( 'Hobbes', 'Simba', 'Grumpy Cat' ), 'dogs' => array( 'Hobbes Dog', 'Simba Dog', 'Grumpy Dog' ), 'birds' => array( 'Hobbes Bird', 'Simba Bird', 'Grumpy Bird' ), ); //Parsing Request :: Take the ...


0

As user9279 suggested (albeit a bit hard to understand), go to your Settings -> Permalinks and save them again. This tends to fix issues like this (as well as, for example, a 404 when viewing a newly created custom post type). If this doesn't work, I suggest you look at the order of the registration for the taxonomy / post. The taxonomy should exist before ...


6

This is the approach to add a rewrite rule for swapping out the template that WP wants to render (usually the 404 template) with something else. In your case you're just wanting to die with some JSON data so there are a bunch of different ways to do this. This is the "by the book" approach to adding a rewrite rule instead of a hack to check the URL on your ...


1

You can use pre_get_posts as suggested but simply check the global $wp object for the request url.. like so: add_action( 'pre_get_posts', function ($query ){ global $wp; if ( !is_admin() && $query->is_main_query() ) { if ($wp->request == 'cats'){ header('Content-Type: application/json'); $cats = ...


1

It seems to me you could use pre_get_posts action hook to modify the query, but it feels a bit of a hack. Anyways, something like this ? add_action( 'pre_get_posts', 'cats_endpoint' ); function cats_endpoint($query ){ if ( !is_admin() && $query->is_main_query() ) { if ($query->query_vars['post_type'] == 'cats'){ ...


3

The easiest way I can think of (and the only one) is create a page with the permalink you're indicating, create a custom template in your theme folder, let's say it's json_output.php with the following content: <?php /* * Template Name: JSON Output */ header('Content-Type: application/json'); $cats = array('Hobbes', 'Simba', 'Grumpy Cat'); echo ...


0

I’m sure there are better ways to do it, but I’d add this to functions.php… add_action('parse_request', 'json_cats'); function json_cats() { if(!empty($_SERVER['REQUEST_URI']) || isset($_SERVER['argv'])) { $urlvars = explode('/', $_SERVER['REQUEST_URI']); if( ( isset($_SERVER['argv']) && count($_SERVER['argv']) > 1 && ...


0

Add this to your functions.php file, and note that you'll need to grab and edit the capabilities for each post type (Post, Page and Attachment) and taxonomy (Category and Post Tag). You should note that there are more capabilities than those listed, but I don't believe that the need changing. Therefore I advise you to output the default capabilites for ...


0

The only way I can see this working is by setting a couple of redirect rules in your .htaccess file. You'd have to manually redirect all your posts (that you want with that permalink structure) and prepend the /awesome URL part in front. Other than the aforementioned solution, which is a hack more than anything, I'm afraid that what you're looking for is ...


2

The permastruct /%category%/%postname%/ will include the categories and subcategories in the URL from top to first assigned child. So, if you want the URL be site.com/source/books/moby-dick/*postname*, you have to assign the post only to "Moby Dick". Assigning the post only to "Moby Dick" category will still show the post under "source" and "books" category ...


0

It is not possible to directly set a referrer. See: http://stackoverflow.com/questions/14235377/http-referer-and-bookmark You can still track this data by passing a parameter in the url and then listening for that parameter in WordPress. For example, you could set the parameter from_desktop in the url, so your url would look like ...


0

Update your DOMAIN site. Put this in your wp-config.php file define('WP_HOME','http://example.com'); define('WP_SITEURL','http://example.com'); Probably thats fix your problem. Wherever, you can revert back to the Default Theme, renaming the folder of your current theme in /wp-content/themes/ directory. Trying too deleting your .htaccess file Regards.


0

You can try this (sorry, not previously tested). See comments inline for explanation: RewriteEngine On ## if any string separated by | is matched, it will append to ?page= RewriteRule ^(members|add-members|delete)$ admin.php?page=%1 [L,E=CLEAN_CONTACT_URL:1,QSA] ## If querystring starts with page= and is followed by any string separated by | ## put that ...


0

I don't know if you can use pages for your purpose, but as in the comments in wp-includes/post.php line 3701 (in the wp_unique_post_slug function), you can use identical slugs for pages in different trees: /* * Page slugs must be unique within their own trees. Pages are in a separate * namespace than posts so page slugs are allowed to overlap post slugs. ...



Top 50 recent answers are included