WordPress.org

Ready to get started?Download WordPress

Forums

Create a random number when a post is added (11 posts)

  1. t3ch33
    Member
    Posted 6 years ago #

    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?

  2. MichaelH
    Member
    Posted 6 years ago #

    "Of course, I already know what code to use"

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

  3. t3ch33
    Member
    Posted 6 years ago #

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

  4. Jonathan Landrum
    Member
    Posted 6 years ago #

    nm

  5. t3ch33
    Member
    Posted 6 years ago #

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

  6. mildlyhotpeppers
    Member
    Posted 6 years ago #

    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.

  7. t3ch33
    Member
    Posted 6 years ago #

    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.

  8. whooami
    Member
    Posted 6 years ago #

    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.

  9. t3ch33
    Member
    Posted 6 years ago #

    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.

  10. whooami
    Member
    Posted 6 years ago #

    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?

  11. whooami
    Member
    Posted 6 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic