• I just converted to WordPress and want to keep the same format of my old site, which includes an ‘article id’ in the url. The article id is just a random number and unique number that’s created once the article is posted. Of course, I already know what code to use. I need to know where to put the code. Please be specific. Also, since I will use this in the post’s url, how would I go about doing that in the Permalinks section?

Viewing 10 replies - 1 through 10 (of 10 total)
  • “Of course, I already know what code to use”

    Might want to post that code so the experts can provide a clear explanation.

    Thread Starter t3ch33

    (@t3ch33)

    it’s just basic code that creates a random number. $post_id=rand(1, 100);

    nm

    Thread Starter t3ch33

    (@t3ch33)

    jonlandrum, it can’t be seconds. It has to be the random number that I define (certain length, etc). Thanks anyway.

    Why not just use the post’s id instead? Seems a lot easier than making your own random number…plus there’s a x% chance of the number being repeated, where x is the number of existing posts…if you use a number between 1 and 100, that is.

    Thread Starter t3ch33

    (@t3ch33)

    mildlyhotpepper, thanks, but I don’t want to use the post_id. I want links to have the same format as links that were created before I installed WP. My old blog script that I made checks for duplicates, so the random number is not an issue. Someone who knows what they’re doing should just be able to tell me where the code goes. I’m still looking for a solution. Thanks.

    you have what three threads going, all for the same purpose?

    Ive answered your question in one of the other threads. If you want to assign random post_ids then you need to modify the query responsible for inserting the post into the database.

    Its not assigned until the post is created, and its not assigned as a function of wordpress. Common sense would tell you that assigning a # to something and then expecting that same # to be available BEFORE the application has actually looked in the database would not work.

    In other words, the post_id is a result of the insertion of the post into my_sql.

    if you look at whats going on on the create new post page, you will notice this:

    <input type='hidden' id='post_ID' name='temp_ID' value='-1202190743' /><script type="text/javascript">

    its unset. until you click submit.

    Thread Starter t3ch33

    (@t3ch33)

    If you want to assign random post_ids then you need to modify the query responsible for inserting the post into the database.

    If you would actually read my question, you will realize that is what I am asking for. I was quite clear, but maybe there’s a language barrier. Don’t bother offering more ‘help,’ because you’re just wasting my time when your only solution is to repeat my question.

    I am still looking for a *working* solution. If someone actually knows what they’re doing, please let me know. Thanks.

    If you would actually read my question, you will realize that is what I am asking for. I was quite clear, but maybe there’s a language barrier.

    So, youre saying I provided the answer, but im supposed to re-read the question? And there is a language barrier? Despite the fact that I KNEW what you were asking for?

    Perhaps for you? Im a native English speaker and reader.

    Someone else recommended it, in your THIRD thread on this topic, and Im going to reiterate their advice.

    Go get wingrep > at wingrep.com and use it.

    Ive already told you *where* you need to start looking, havent I?

    oke, so your lucky im feeeling bored. Here is specifically what you are loking for:

    Inside wp-admin/includes/post.php, look for :

    function wp_write_post

    within it you will find:

    // Create the post.
    	$post_ID = wp_insert_post( $_POST );

    wp_insert_post can be found inside wp-includes/post.php at Line 601.

    Thats what you need.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Create a random number when a post is added’ is closed to new replies.