Home Forums Paid Support [Closed] Wrong permalink base for child posts

[Closed] Wrong permalink base for child posts

This topic contains 16 replies, has 3 voices, and was last updated by  Ghennadi 9 months, 3 weeks ago. The support staff assigned to this topic is Ghennadi.

Viewing 15 posts - 1 through 15 (of 17 total)
Author
Posts
#170851

I have a custom post type "artists" whose posts are assigned as child posts to several pages (e.g. "photography", "painting") via WP Types.
Shouldn't the permalink now look like /%page-name%/%artist-name% (e.g. /painting/picasso)?
When I go to this site I will always be redirected to /artists/%artist-name%

#170928

Adriano
Forum moderator

Dear Lukas,

Please attach here an image from the this custom post type settings. Would be nice a full screen image.

#170951

I hope work with these even though they are in German. I don't know how to set English as language.

#170986

Additional Question referring to this topic:

My Custom Post Types's Data is supposed to be split outputted on virtual subpages (like: /%page_name%/%artist_name%/%subpage_name%
So I got for example two textareas "press" and "vita"; in my single-artist.php there is a switch/case which compares the "subpage_name" of the query to "press" and "vita" and outputs the appropriate data.
Which query variables do I need to use in my rewrite_rules? It should be something like: index.php?artist=xxx&subpage_name=xxx&wptypes_parent_post_slug=YYY
So I can use the variable (wptypes_parent_post_slug or whatever) in my rewrite rules.

#171307

Adriano
Forum moderator

I’ll send you a private email right now asking you for some private information that will help me debug this issue for you. Please check your email in a couple of minutes, and if you don’t get it, let me know so I can send it again.

#173136

Dear Adriano,
could you find any solution to this problem yet?
Thanks!

#174233

Ghennadi
Forum moderator

Dear lukasB,

With Types plugin you can't modify URL structure.
You can mix custom post type taxonomy and this plugin http://wordpress.org/plugins/hierarchical-urls/

Also, you can read some info about how to create custom URL structure at http://www.hongkiat.com/blog/wordpress-url-rewrite/

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Gen.

#174305

Dear Ghennadi,

in a default WordPress Environment you can create pages and you can create child pages to these pages. The permalink to a child page would be for example /parent-page/child-page. This is not possible with custom post types.
The plugin Types introduces this feature also to custom post types and so it also has to modify the rewrite rules to work like /parent-page/child-custom-post-type. Actually, this redirects me to /name-of-custom-post-type/child-custom-post-type. So declaring the parent as parent have not brought me any advantage.

So it is necessary to modify the rewrite rules. It should be something like:

add_rewrite_rule(
"([^/]+)/([^/]+)/?",
"index.php?wpt_parent=$matches[1]&name-of-custom-post-type=$matches[2]",
"top");

You see, for the rewrite rules I need to know the real name of the variable I called in the example "wpt_parent". Then I could visit:
index.php?wpt_parent=photography&artist=sam-sample
and it should output the artist's page. If I just visited index.php?wpt_parent=photography only those posts should be output (like archive.php) which are declared as child posts of the page photography by WP Types.

(For better understanding I am using "Sam Sample" as the desired child-custom-post-type; custom post type is "artist" and parent page is "photography")

Do you understand my explanations?

#174483

Is it correct, that "_wpcf_belongs_artist_id" is a custom field key?
So one approach would be to add this to the query like:

function wpa_filter_home_query( $query ){
    if( $query->is_main_query()
    && isset( $_GET['_wpcf_belongs_artist_id'] ) ) {
        $meta_query = array(
            array(
                'key' => '_wpcf_belongs_artist_id',
                'value' => array( $_GET['_wpcf_belongs_artist_id'] )
            )
        );
        $query->set( 'meta_query', $meta_query );
    }
}
add_action( 'pre_get_posts', 'wpa_filter_home_query' );

Doing this, my aim is still to get the correct post with "index.php?_wpcf_belongs_artist_id=24&artist=sam-sample" (24 is a sample id for the parent page) as a first step. Once this is working I can think about rewrite rules.

#174659

Ghennadi
Forum moderator

Dear lukasB,

Yes, if you can get send _wpcf_belongs_artist_id variable it's will work.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Gen.

#174689

But in fact, this does not work for me.
And shouldn't this work by default?

#174696

Ghennadi
Forum moderator

Dear lukasB,

First of all, you must add rewrite rule ( more info at: http://codex.wordpress.org/Rewrite_API/add_rewrite_rule ), otherwise wordpress will show empty page or 404 error page.

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Gen.

#174748

Shouldn't work this by default?

This is what I tried:

add_action('init', 'rewrite_rules');
function rewrite_rules(){

  /* I tried with and without add_rewrite_tag */
  add_rewrite_tag('%_wpcf_belongs_artist_id%', '([^&]+)');

  add_rewrite_rule(
  	"([^/]+)/([^/]+)/?",
  	"index.php?_wpcf_belongs_artist_id=$matches[1]&artist=$matches[2]",
  	"top");
  flush_rewrite_rules();
}

It doesn't work. How should it work? This:
index.php?_wpcf_belongs_artist_id=24&artist=sam-sample
redirects me to:
/artist/sam-sample/?_wpcf_belongs_artist_id=24&artist=sam-sample
and outputs that no posts were found.
This:
index.php?_wpcf_belongs_artist_id=24
doesn't redirect but only outputs that no posts were found.

If I deactivate my function wpa_filter_home_query() explained above, this:
index.php?_wpcf_belongs_artist_id=24&artist=sam-sample
redirects me to:
/artist/sam-sample/?_wpcf_belongs_artist_id=24&artist=sam-sample
with the correct output of the single artist post.
This:
index.php?_wpcf_belongs_artist_id=24
just outputs my front page.
The only more or less working example is with the same settings:
/photography/sam-sample/?artist=sam-sample&_wpcf_belongs_artist_id=24 and:
/photography/sam-sample/?artist=sam-sample
These DON'T redirect me to /artist/sam-sample/… but output the correct single artist post.

btw my whole site seem to load very slow since I am working on that problem.

Please give me specific answers. I buyed plugins from you and you offer support for them. This is an issue which should work by default but it doesn't. I also gave approaches to the solution and you just repeated them.

#174760

There must be a rewrite rule specified somewhere, because this:
/photography/sam-sample
redirects to this:
/artist/sam-sample

But I can not find it. I don't know if this is specified in WordPress's default code or in your plugin. I suppose in your plugin.

#175043

Ghennadi
Forum moderator

Dear lukasB,

Type by default not allow this URL structure. We understand this feature request, but we cannot implement it because our analysis shows that it might cause serious compatibility problems with newer WordPress versions, themes and other plugins.
You can ask help from our certified partners at http://wp-types.com/consultant/

Please let me know if you are satisfied with my answer and if I can help you with any other questions you might have.
Regards,
Gen.

Viewing 15 posts - 1 through 15 (of 17 total)

The topic ‘[Closed] Wrong permalink base for child posts’ is closed to new replies.

Support Policy

ToolSet staff will help you use Types, Views and CRED correctly, provide any information you need, help troubleshoot problems and advice on best-practices.

Please make sure to issue only one topic per each support ticket.

Need custom programming work for your site? Check out our certified partners.