• herculesnetwork

    (@herculesnetwork)


    hello staff wordpress.org
    I need help from you again,

    this function shuffle numbers,

    function gen_num()
    {
    $caracteres = “012345678910111213141516171819”;
    $mistura = substr(str_shuffle($caracteres),0,15);
    print $mistura;

    I needed a condition to print or not the numbers at the posts, and the @leglesslizard User helped me. It works perfectly,

    function gen_num()
    {
    global $post;
    $mistura = get_post_meta( $post->ID, ‘my_custom_meta’, true );

    if ( ” == $mistura ) {
    $caracteres = “012345678910111213141516171819”;
    $mistura = substr(str_shuffle($caracteres),0,10);
    update_post_meta( $post->ID, ‘my_custom_meta’, $mistura );
    }

    print $mistura;
    }

    I am now trying to make arrays and I can not!

    function shuflenames()
    {
    $input = array(“Neo”, “Morpheus”, “Trinity”, “Cypher”, “Tank”);
    $rand_keys = array_rand($input, 2);
    echo $input[$rand_keys[0]] . “\n”;
    echo $input[$rand_keys[1]] . “\n”;

    my failed attempt:

    function shuflenames()
    {
    global $post;
    $input = get_post_meta( $post->ID, ‘names’, true );
    if ( ” == $input ) {
    $input = array(“Neo”, “Morpheus”, “Trinity”, “Cypher”, “Tank”);
    $rand_keys = array_rand($input, 2);
    update_post_meta( $post->ID, ‘names’, $input );
    }
    echo $input[$rand_keys[0]] . “\n”;
    echo $input[$rand_keys[1]] . “\n”;
    }

    Thanks to all, Best Regards.

Viewing 1 replies (of 1 total)
  • Thread Starter herculesnetwork

    (@herculesnetwork)

    the best I could to try to work was this:

    function descriptiongen()
    {
    global $post;
    $mixword = get_post_meta( $post->ID, 'description', true );
    if ( '' == $mixword) {
    $input = array("Neo", "Morpheus", "Trinity", "Cypher", "Tank");
    $rand_keys = array_rand($input, 2);
    update_post_meta( $post->ID, 'description', $mixword );
    }
    echo $input[$rand_keys[0]] . "\n";
    echo $input[$rand_keys[1]] . "\n";
    }

    but the words change as the condition does not exist. every new access words are changed, they are not actually written in the posts

Viewing 1 replies (of 1 total)
  • The topic ‘how to apply a print condition in an array?’ is closed to new replies.