how can i show only the parents in owl-carousel?

According to the documentation, you would have to use post_parent => 0 So your code would look like this: <div class=”owl-carousel owl-theme”> <?php $c = 0; $q2 = new WP_Query( array( ‘post_type’ => array( ‘post’, ‘book’ ), ‘post_status’ => ‘publish’, ‘post_parent’ => 0, //add this here ‘orderby’ => ‘modified’, ‘order’ => ‘desc’ ) ); while … Read more

tax_query operator woes

I’m not sure that there is a way to get it to use ‘OR’ instead of ‘AND’. Alternatively, you can do: $myquery[‘tax_query’] = array( ‘relation’ => ‘OR’, array( ‘taxonomy’ => ‘regions’, ‘terms’ => array(‘region1’), ‘field’ => ‘slug’, ‘operator’ => ‘IN’ ), array( ‘taxonomy’ => ‘population’, ‘terms’ => array(‘pop1’), ‘field’ => ‘slug’, ‘operator’ => ‘IN’ ), … Read more

WordPress Plugin Dev: Using array for WP options

If you are using the Settings API then you don’t have to save the options, that’s done for you. So when using an array to store the options your validation function should get an array of all existing options, update only the changed and return that array. Something like this: function my_settings_option_validate( $input ) { … Read more

Working with query_posts ( arrays and query strings)

I’d suggest not using $query_string to simplify things. If you’re using an array, stick with the array form for the query variables: global $wp; $paged = ((int)get_query_var(‘paged’)) ? (int)get_query_var(‘paged’) : 1; $s_array = array( ‘post_type’ => ‘blog’, ‘caller_get_posts’ => 1, ‘paged’ => $paged, ‘meta_query’ => array( array( ‘key’ => ‘votes_percent’, ‘value’ => ’50’, ‘compare’ => … Read more

Passing Custom Field Data as Array to be Saved (Resulting Custom Field Array is inconsistent)

Definite solution: Seeing as wp’s core get_post_custom function returns multiple data fields saved as a single key in a random order, I resolved the issue by writing a function to replace it – which has some added flexibility: /*————————————————————— Function: Retrieve post meta field for a post based on ID Usage: [admin/meta_box/downloads.php] = to replace … Read more

PHP get the first post separately from array returned by wpdb->get_results()

once you have set of result in particular order you can achieve it simply as below : – $pageposts=$wpdb->get_results(” SELECT * FROM $wpdb->posts WHERE post_type=”post” AND post_status=”publish” ORDER BY post_date DESC LIMIT 6 “, OBJECT); First time $i=1; foreach($pageposts as $pageposts_first){ //here goes your first post if($i==1) break; } For rest of posts $i=0; foreach($pageposts … Read more

WP Query Returning All Posts

I think you’re confusing old meta parameters with new meta_query parameters. meta_key should be just key and meta_value should be just value. Refer to WP_Query in Codex for correct syntax. Also, print_r( $country_query ); will show you the actual SQL query being sent to the database and will show you where you’re going wrong.

Save an array from drop-down in custom meta box

Quite simple. Instead of saving the post title, save the post ID, so in the front end you can extract all necessary info. Like so: get_post( $the_saved_ID_value ); or get_permalink( $the_saved_ID_value );. In you code, change this line: echo ‘<option value=”‘.get_the_ID().'” ‘.$is_selected.’>’.get_the_title().'</option>’; Notes: Using a WP_Query seems a bit too much, consider get_posts. Lots of … Read more

Shortcodes and a list of IDs?

explode will be your best option. WordPress has a few built in functions to handle arrays of function arguments (wp_parse_args and shortcode_atts for example), but nothing relating to splitting a string and iterating the result. It’s not entierly clear to me what you are trying to achieve, but let’s say you were trying to get … Read more