Notifications
Clear all

Script How can permanently use the topic id for slug

15 Posts
3 Users
1 Likes
305 Views
Posts: 17
Topic starter
(@kilany)
Eminent Member
Joined: 2 years ago

Hi there 

 

I am sking about how can permanently use the topic id for slug ?

 

Becasue I see some post saying will add this https://wpforo.com/community/how-to-and-troubleshooting-2/how-to-use-post-ids-in-url-instead-of-title-slug/paged/2/

14 Replies
adisaputro
Posts: 98
(@adisaputro)
Estimable Member
Joined: 4 years ago

AFAIK, we can't using topic id as permanent slug, only for short link.

Reply
Robert
Posts: 9966
Admin
(@robert)
Support Team
Joined: 7 years ago

@kilany,

I'm sorry, but there is no way to use ID based URLs in forum. It's only available as a quick link. We're not planning to add it in the near future.

Reply
Posts: 17
Topic starter
(@kilany)
Eminent Member
Joined: 2 years ago

I can do this from database why you do not give to us this options ? Every time I do this manually to change for every new topics on phpmyadmin.

 

Posted by: @robert

We're not planning to add it in the near future.

You should give us the freedom to use whatever we want because it is really annoying when the name is long and inconsistent with other languages while in English there is no problem

 

Reply
1 Reply
adisaputro
(@adisaputro)
Joined: 4 years ago

Estimable Member
Posts: 98

@kilany I agree with you

Reply
Robert
Posts: 9966
Admin
(@robert)
Support Team
Joined: 7 years ago

@kilany,

You can set the topic ID as the topic slug using hook code.

Put this code in a PHP snippet using Code Snippets plugin or in the functions.php file of your current active WordPress theme:

add_filter('wpforo_add_topic_data_filter', function( $args ){
if( wpfval($args, 'slug') ){
$topicid = WPF()->db->get_var("SELECT MAX(`topicid`) as topicid FROM `" . esc_sql( WPF()->tables->topics ) . "`");
if( $topicid ){
$args['slug'] = (string) ( intval($topicid) + 1 );
}
}
return $args;
}, 10);
Reply
9 Replies
(@kilany)
Joined: 2 years ago

Eminent Member
Posts: 17

@robert

Thank you very much. It works. I really appreciate this 😍 

Is there a way to shorten the name of the forum, for example?

example.com/forum/experience/1

domain / forumname / subforum / postID

The name of the forum and the name of the section, can I make them abbreviated to be for example with out the subforum

example.com/forum/1

Reply
Robert
Admin
(@robert)
Joined: 7 years ago

Support Team
Posts: 9966
Posted by: @kilany

The name of the forum and the name of the section, can I make them abbreviated to be for example with out the subforum

I'm sorry, but there is no way to do a structural change in URL.

Reply
(@kilany)
Joined: 2 years ago

Eminent Member
Posts: 17

@robert I create two posts they give same post ID on browser but on Database is okay it's have ID for each, So I mean it's make same slug for each creating post

 

 

Reply
Robert
Admin
(@robert)
Joined: 7 years ago

Support Team
Posts: 9966

@kilany,,

I've just updated the code, please copy again and replace the old one in your website.

Reply
(@kilany)
Joined: 2 years ago

Eminent Member
Posts: 17

@robert its still same number slug fixed on number 2

Reply
Robert
Admin
(@robert)
Joined: 7 years ago

Support Team
Posts: 9966

@kilany,

That's just impossible. Are you testing on a live website? The code has been tested on 5 different hostings and on localhost, it works fine. Please make sure you've copied and pasted the source code correctly, leave some screenshots.

Reply
(@kilany)
Joined: 2 years ago

Eminent Member
Posts: 17

@robert I am using Cloudflare so I wanna check it

Reply
(@kilany)
Joined: 2 years ago

Eminent Member
Posts: 17

@robert I test it on another WP that still slug fixed number

Reply
Robert
Admin
(@robert)
Joined: 7 years ago

Support Team
Posts: 9966

@kilany,

Something wrong with your database setup. It seems your WordPress doesn't have access to MySQL's information_schema.tables. This is an unusual issue.

In any case, I just updated the script. It should work in your case as well. Please delete the previous script. Again, make sure it's deleted, then copy and use the new script.

Reply