WordPress loop: Display if posts exist

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

Creating Custom Query

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 );

WordPress Query Returning Every Post

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

Showing all post from all post type in admin backstage

You can use a $wpdb->get_results for this. I am not an mySQL expert so I will give you the pseudo code instead global $wpdb; $data = $wpdb->get_results( SELECT posts.ID ID, posts.post_title title, posts.post_author author, postmeta.isbn isbn FROM $wpdb->posts posts JOIN $wpdb->postmeta postmeta ON posts.ID = postmeta.post_id WHERE posts.post_type=”post_type_1″ OR ‘post_type_2’ OR ‘post_type_3’ GROUP BY posts.ID … Read more

create functions based on array values

Can you use the __call PHP class functionality? http://www.php.net/manual/en/language.oop5.overloading.php#object.call You could use __call in your class and call your function for grabbing the page types and check them against the $name (first) argument and running custom code against it. For instance: __call ($name, $args) { $types = array (‘type_a’, ‘type_b’, ‘type_c’); if (in_array($name, $types) { … Read more

Insert dynamic content into posts

Everytime you upload a new image, the afip_new_post_content filter is called which can be used to change the post content before creation – http://wordpress.org/extend/plugins/automatic-featured-image-posts/ Assuming you have a list of URLs stored somewhere – like in the database – you need a function that would get a url from this list, then delete the url … Read more

posting twice from an array?

You could try something like this: $postTitle=””; // save post title if(isset( $_POST[‘submit’])){ // if submit button is present $vergoeding=$_POST[‘vergoeding’]; $extrakosten=$_POST[‘extrakosten’]; for ($i=0; $i < count($vergoeding); $i++) { $new_post = array( ‘post_title’ => $postTitle, ‘post_content’ => ‘ ‘, // can not be empty ‘post_status’ => ‘publish’, ‘post_type’ => ‘landschapselement’ // custom post type ); $pid … Read more

shortcodes inside shortcode to sum values

You can try this: add_shortcode(‘sumsc’,’sumsc_func’); function sumsc_func( $atts, $content = null ) { $sum=0; preg_match_all(‘/stat([0-9]+)/i’, $content, $matches); if(isset($matches[1])){ $sum = array_sum($matches[1]); } return do_shortcode($content).” <div>The sum is <strong>”.$sum.”</strong></div>”; } This will add the total sum at the end of the shortcode content. Usage example: You can try this in your editor: [sumsc][stat1 val=”usa”] [stat2 val=”europe”] … Read more