First off I'm a total noob and no almost nothing about PHP. I had someone help me with the following code. It's a WP plugin that remotely posts to other sites. I am trying to make it so that I can add random keywords to the title and permalink. The issue is when it posts for some reason it posts all the keywords instead of picking one. Can anyone see any problems with this section of the code? It's the only part that's been edited. function syn_syndicate_box() { global $syn_multi_curl; $syn_multi_curl = new MultiCurl(); $options = syn_get_admin_options(); $keywords1 = array("Keyword", "Keyword", "Keyword", "Keyword", "Keyword", "Keyword", "Keyword"); $keywords2 = array("Keyword", "Keyword", "Keyword", "Keyword", "Keyword", "Keyword", "Keyword"); $post = wp_get_single_post( $_GET[ 'post_id' ] ); $title = $post->post_title; $permalink = get_permalink( $post->ID ); $content = $post->post_content; $content = strip_tags( $content ); $content = substr( $content, 0, $options[ 'excerpt_length' ] ); $needle = chr( 194 ) . chr( 160 ); $content = str_replace( $needle, ' ', $content ); $options[ 'bitly_url' ] = syn_shorten_url( $options, $permalink ); $sites = syn_get_sites(); foreach ( $sites as $site ) { $randomNumber1 = rand(0, count(keywords1)-1); $randomNumber2 = rand(0, count(keywords2)-1); $keyword1 = $keywords1[$randomNumber1]; $keyword2 = $keywords2[$randomNumber2]; $title = $keyword1 ." " . $title . " " . $keyword2; $site = str_replace( ' ', '_', strtolower( $site ) ); if ( isSet( $_POST[ $site . '_enabled' ] ) ) { try { call_user_func_array( 'syn_post_' . $site, array( $options, $title, $content.'<p><strong><a href="' . $permalink . '">' . $title . '</a></strong></p>' )); Code (markup):
I don't see a problem at first glance. You should be using array_rand() to pull random elements from the array though.
Ok I'll try that thanks. I must have put it in the wrong place or something because I get this error: Warning: array_rand() [function.array-rand]: First argument has to be an array
The first variable you put in array_rand() has to be an array... that should have been fairly obvious.