Hot answers tagged

15

The following code will work, but you just have to keep in mind that conflicts can happen easily if the slug for your custom post type is the same as a page or post's slug... First, we will remove the slug from the permalink: function na_remove_slug( $post_link, $post, $leavename ) { if ( 'events' != $post->post_type || 'publish' != ...


8

I tried to figure this out not long ago and the short answer from what I know is no. Not from within the rewrite argument at least. The long explanation becomes apparent if you look at the actual code of register_post_type in wp-includes/post.php line 1454: add_permastruct( $post_type, "{$args->rewrite['slug']}/%$post_type%", $permastruct_args ); You ...


7

You can use template_include, but before you hook to this filter you must do the following steps: Create page template. e.g: page-target.php <?php /** * Template Name: Page Target */ ... Manually query the contents of target-page on page-target.php template, because the global $post will be referencing to your some-prefix-* page. (Optional): Edit ...


5

I am not sure if this is the best solution or not, but it works: function movie_review_permalink( $url, $post, $leavename ) { $category = get_the_category($post->ID); if ( !empty($category) && $category[0]->slug == "test" ) { //change 'test' to your category slug $date=date_create($post->post_date); $my_date = ...


5

I want ot give you an "alternate" approach. I'm pretty sure you're not going to follow this, but I thinks is interesting to read. OOP "routing" approach In WordPress, "pretty" urls are mathed to "ugly" urls. But most web frameworks (not only PHP) uses the concept of "routing": to match an url to an "action" (or a controller). I want to give you an idea ...


4

yes, but: it might be hard if drupal mixes several types of content under the /node/ parent. Those are not very SEO or even human freindly URLs so you might actually want to change them and just have a redirect from the old one to the new one.


4

Note that search engines might not like multiple paths to the same content! Here I assume you want e.g.: example.tld/some/path/to/painting-orange example.tld/painting-blue example.tld/painting-red example.tld/painting-yellow to behave like it was this page: example.tld/paintings but not so for paths like: ...


4

The Why Part If we have a page called technical and try to load: example.tld/technical/99999999999999999999 then the 99999999999999999999 part is treated as a page query variable with the value of 2147483647. The reason is this rewrite rule for pages: according to the handy Monkeyman Rewrite Analyzer by Jan Fabry. This part of the ...


3

In response to my previous answer: you could of course set the rewrite parameter to false when registering a new post type and handle the rewrite rules yourself like so <?php function wpsx203951_custom_init() { $post_type = 'event'; $args = (object) array( 'public' => true, 'label' => 'Events', 'rewrite' ...


3

Yes it is possible, but there isn't much point in that. The crudest way is to use a filter on the result of getting the 'rewrite_rules' option, and manipulating it by adding the entries you require directly to the array, and then you might need to filter those rules out when the option is updated. The thing is that it is most likely a waste of time as as in ...


3

It was woocommerce, it has a setting "geolocalize users with cache support" which adds this parameter to every single url and link. I noticed that the hash appended was the same in every browser on my computer, so I realized it wasn't a "session" hash, but an IP address hash.


3

Well, AUTH_KEY and it´s brothers where introduced in WordPress 2.6 to improve safety for logged in users. They are used to encrypt and validate the information in your backend login cookie. While revealing the AUTH_KEY alone might not be a real security issue, you should nevertheless not output/use this anywhere to give less surface for attacks. ...


3

Retrieve "type" of query from url: Previous suggestions As noted in the linked answer, there's url_to_postid(). This will just get you the ID of the object at that endpoint. Long story short, this function will only return an ID and then run a new \WP_Query to get the post type object from the DB and finally return the URl – if there is any and _if it is ...


2

I am not sure whether you have hooked this function to appropriate action. Also you have not concatenated the strings properly: Instead of $newdestinationurl = $url/$destinationurlslug ; it should be $newdestinationurl = $url."/".$destinationurlslug ; Please see below for the complete code: function ninja_forms_handler() { add_action ( ...


2

Endpoints are for adding extra query vars to existing routes, I think you just want a vanilla rewrite rule here: function wpd_media_image_rewrite_rule() { add_rewrite_rule( '^image/([^/]*)/?', 'index.php?post_type=attachment&name=$matches[1]', 'top' ); } add_action( 'init', 'wpd_media_image_rewrite_rule' ); You might ...


2

Caveat: the code examples within this answer are very basic and may or may not need further conditional logic to adapt to your precise needs, this logic is meant as an example to get you on your way. There's two considerations you need to be aware of: Consideration 1: If you add a new post and save it with a post_status of draft first, the post will not ...


2

WordPress tries to guess what post the user want to see by post name. That is what is making both example.com/new-bikes/ktm/duke/ktm-690-duke-2012/ and example.com/new-bikes/ktm/yamaha/ktm-690-duke-2012/ return the same and "correct" content. What is important is that, if you see at the source code of example.com/new-bikes/ktm/yamaha/ktm-690-duke-2012/, you ...


1

OK, here's what I got working in the end. I'm honestly not sure if I've sanitised the parameters correctly so input welcome there! Other than that, all works as intended. Big thanks to Pieter Goosen! // action add_action('pre_get_posts', 'my_pre_get_posts', 10, 1); function my_pre_get_posts( $query ) { // bail early if is in admin if( is_admin() ) ...


1

You need to build a proper meta_query. Your code will only work when you have one meta_key set, if you have more than 1, everything will be haywire. Also note, you should never ever use any unsanitized, non validated values from a $_GET variable (and for that matter any value coming from anywhere). It is extremely easy to inject malicious code into your ...


1

You would want to filter the category link to add the custom variable to the category link. You can make use of the get_term_link filter to filter the category link address Here is a very basic idea: Suppose that we, taken from OP, that you need to add the custom variable only to terms belonging to the build in taxonomy category, and only when we are on a ...


1

@Pat Gilmour is on the right track. The source to handle this is here. First thing you want to do is open the wp-config.phpfile in your SFTP (secure FTP). Add these two lines to your wp-config.php, where "example.com" is the correct location of your site. define('WP_HOME','http://example.com'); define('WP_SITEURL','http://example.com'); Read that ...


1

The best way to fix this is to install PHPmyAdmin and then navigate to the wp-options table and change the site-address row. To install PHPmyAdmin, click on "Browse Marketplace" and search for PHPmyAdmin.


1

You are on the right track. Point your add-on domains to Wordpress root Create Wordpress landing pages Point to landing page using add-on domain Rel=canonical will prevent duplicate indexing penalty All landing page links will automatically point to canonical domain Naturally you will do all your editing from the canonical domain If you run into trouble ...


1

The pattern (.+) matches any character, including the slash, so any combo of parameters will always match your first rule, with anything that follows being passed as the version query var. Change all instances of (.+) to ([^/]+) to match all characters except the slash.


1

You need to tell get_edit_post_link to not use the ampersands as specified in the codex. Try this instead: var pop = window.open(' <?php echo get_edit_post_link(get_the_ID(), ''); ?> ', '_blank', 'screenX=200,screenY=200,width=1000,height=600');


1

I'm going to try to put an answer together based on my understanding of the information provided. I'll outline a couple of assumptions before I start working through the logic: 1) Like Picard you'll bypass the standard WP template hierarchy in favor of an index.php fall through. 2) The endpoints will be provided by the WP REST API plugin. 3) For the sake ...


1

You'r missing $post variable ( it is not defined and that for you don't get post_name ). As a solution you could add global $post; You'r code would be like: <a href="<?php echo site_url('/article/full-text/'); global $post; $slug = $post->post_name; echo $slug; ?>" title="<?php the_title_attribute(); ?>">Full Text</a>


1

404 Possible Error Cases with Permalinks check your apache config and make sure the directory is right. restart the apache process along with MYSQL/similar. make sure mod_rewrite is enabled Apache mod_rewrite for Ubuntu/Debian: sudo a2enmod rewrite sudo service apache2 restart Similliar to mod_rewrite for Nginx by .htaccess: a simpler way is ...


1

This is solution of your 404 links problem, Got to Settings -> Permalinks -> In 'Product permalink base' select the 'Shop base with category' option. For more you can visit, https://wordpress.org/support/topic/permalinks-404-with-custom-post-type



Only top voted, non community-wiki answers of a minimum length are eligible