How can I access ‘key’ and ‘value’ from an array in a for loop?
If I am understanding you correctly just change <?php $count=1;foreach ($value[‘options’] as $key => $option) { ?> and you can access the key from $key.
If I am understanding you correctly just change <?php $count=1;foreach ($value[‘options’] as $key => $option) { ?> and you can access the key from $key.
where exactly? example below is for the count getting shown in brackets after the tag name, outside the link: <?php $tags = get_tags(); if ($tags) { foreach ($tags as $tag) { echo ‘<li><a href=”‘ . get_tag_link( $tag->term_id ) . ‘” title=”‘ . sprintf( __( “View all posts in %s” ), $tag->name ) . ‘” ‘ … Read more
The return set of $children is an associative array. So you can get the IDs with: $children = get_children( $args ); foreach ($children as $k => $v) { echo $k; // do stuff with $v }
You’re doing one to many loops. What you want to be doing is this: $args = array( ‘child_of’ => $CurrentPage ); $children = get_pages( $args ); foreach ($children as $key => $value) { echo $key[‘post_title’]; }; Or you could also: $args = array( ‘child_of’ => $CurrentPage ); $children = get_pages( $args ); foreach ($children as … Read more
Try this code, I’ve removed query_posts and used get_posts instead because I’m not sure if query_posts will work in a shortcode and using get_posts is safer. function featured() { $posts = get_posts(array(‘post_type’ => ‘property’, ‘posts_per_page’ => 2)); if(isset($posts) && !empty($posts)) { foreach($posts as $post) { echo “<div class=\”singlefeatured group\”>”; //I wasn’t sure what you wanted … Read more
Use var_dump($site[0]) to see the structure of the array. And once you know that, then you can properly reference an item in that array. (You could also do var_dump($site) to get a full picture of what’s going on.)
You can use the has_tag function in a conditional statement to achieve what you want. Take a look at the codex page here: Function Reference/has tag. This isn’t 100% tailored to your specific question, but you should see how it’s working and adjust for your specific task: <?php if( has_tag() ) { ?> <?php query_posts( … Read more
I think I got it. You’re querying for sticky posts. Attachments can’t be sticky at least by default. Hence, you’re see the normal loop order when sticky posts are involved. So if you add this to your second args array: ‘ignore_sticky_posts’ => true I think your problem should be resolved. Here’s the relevant codex section … Read more
Try following codes: $country_search_array = array(); while($row = mysql_fetch_array($regionresult)){ $country_search_array[] = $row[‘country’]; // Your country field name } $country_search = “‘”.implode(“‘,”, $country_search_array).”‘”; $args = array( ‘posts_per_page’ => -1, ‘meta_query’ => array( array( ‘key’ => ‘Country’, ‘value’ => $country_search, ‘compare’ => ‘IN’ ) ) ); $query = new WP_Query( $args );
Thanks for all of the help! It tured out to be a combination of issues: Instead of imploding the $country_search_array, it needs to be added as is to the query. Since it’s an array, we can’t use the ‘=’ for the compare value. It needs to be ‘IN’ I couldn’t have figured it out without … Read more