Populate Array with values from another arrray [closed]
You can easily use foreach to achieve that, $my_array = array(); foeach($wpArray as $row){ $my_array[$row->ID] = $row->post_name; }
You can easily use foreach to achieve that, $my_array = array(); foeach($wpArray as $row){ $my_array[$row->ID] = $row->post_name; }
You don’t need the sort within the loop if you pass the correct orderby argument. You’ve got order_by with an underscore, where it should be orderby, no underscore. You can then set paged to the page number you want, and posts_per_page to however many you want on each page. Right now you don’t set a … Read more
if(!empty($_POST)) { $player_name = $_POST[‘first_name’]; $payer_email = $_POST[‘payer_email’]; $payment_gross = $_POST[‘payment_gross’]; $payment_date = $_POST[‘payment_date’]; $payer_id = $_POST[‘payer_id’]; $paypal_str = array($player_name, $payer_email, $payment_gross, $payment_date, $payer_id); print_r($paypal_str); global $wpdb; $wpdb->insert( ‘paypal’, array( ‘name’ => $paypal_str[0], ’email’ => $paypal_str[1], ‘amount’ => $paypal_str[2], ‘player_id’ => $paypal_str[3], ‘date’ => $paypal_str[4] ) ); } Remove the unwanted comma from the array.
This is a simple PHP related question (and those are better asked at StackOverflow.com) and you can find if an index exists within a multi-dimensional array by iterating through it and matching. Something as: function wpse231889_has_user_voted( $user_id, $post_id ) { if ( !empty( ( $voters = get_post_meta( $post_id, ‘voter’ ) ) ) ) { foreach … Read more
This is more a generic PHP question than anything to do with WordPress, but I’d suggest setting the value in the constructor: class test { public $basicCols; public $optList = array( ‘one’ => ‘One’, ‘two’ => ‘Two’ ); function __construct() { $this->basicCols = array( array( ‘title’ => ‘KEY’, ‘field’ => ‘slug’, ‘options’ => $this->optList ), … Read more
if the artist names and track names are in matching order and the same in number then: <?php $artists = get_post_custom_values(‘Artist’, $post->ID); $tracks = get_post_custom_values(‘Track’, $post->ID); $i=0; foreach ( $artists as $key => $value ) { $class = ( $i % 2 ) ? ‘alternative’ : ”; // modulus operator echo ‘<li class=”‘ . $class … Read more
Why don’t you just do: <?php global $post; $args = array( ‘post_type’ => ‘post’, ‘post_status’ = ‘publish’, ‘posts_per_page’ => ’10’, ‘meta_query’ => array( array( ‘key’ => ‘fruit’, ‘value’ => ‘apple’ ) ) ); $custom_query = new WP_Query( $args ); while( $custom_query->have_posts() ): $custom_query->the_post(); ?> <?php the_title(); ?> <?php endwhile; wp_reset_query(); ?>
It is probably because of either different versions of PHP or different configuration for the Error logging. Assuming you have same environment (cart status, blog status, logged in user status etc) To overcome this, Please initialize $totals with empty array in the start of the function. And, If you want error to show up for … Read more
Try using: array_merge( $arr, $results ); Instead of: foreach ( $results as $result ) { $arr[] = $result; }
If two fields are named people[name], only the last value will be sent with the form. To be completely reliable, you’ll need to use an id for each person you’re collecting details on: <input name=”people[0][name]”> <input name=”people[0][email]”> <input name=”people[1][name]”> <input name=”people[1][email]”> … Use an incrementing counter in your while loop to do this ($i): <?php … Read more