Notifications
Clear all

Script [Closed] How can permanently use the topic id for slug

15 Posts
3 Users
1 Reactions
811 Views
Posts: 23
Topic starter
(@kilany)
Eminent Member
Joined: 4 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: 128
(@adisaputro)
Estimable Member
Joined: 6 years ago

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

Robert
Posts: 10591
Admin
(@robert)
Support Team
Joined: 9 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.

Posts: 23
Topic starter
(@kilany)
Eminent Member
Joined: 4 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

 

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

Estimable Member
Posts: 128

@kilany I agree with you

Robert
Posts: 10591
Admin
(@robert)
Support Team
Joined: 9 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);
9 Replies
(@kilany)
Joined: 4 years ago

Eminent Member
Posts: 23

@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

Robert
Admin
(@robert)
Joined: 9 years ago

Support Team
Posts: 10591
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.

(@kilany)
Joined: 4 years ago

Eminent Member
Posts: 23

@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

 

 

Robert
Admin
(@robert)
Joined: 9 years ago

Support Team
Posts: 10591

@kilany,,

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

(@kilany)
Joined: 4 years ago

Eminent Member
Posts: 23

@robert its still same number slug fixed on number 2

Robert
Admin
(@robert)
Joined: 9 years ago

Support Team
Posts: 10591

@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.

(@kilany)
Joined: 4 years ago

Eminent Member
Posts: 23

@robert I am using Cloudflare so I wanna check it

(@kilany)
Joined: 4 years ago

Eminent Member
Posts: 23

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

Robert
Admin
(@robert)
Joined: 9 years ago

Support Team
Posts: 10591

@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.