How to hide image-url if no attachment?

Assuming you’re following this tutorial: http://wp.tutsplus.com/tutorials/automagic-post-thumbnails-image-management/ Replace the echo statement at the end of get_attachment_picture with a return, then change your image code. Here is your new image code: // get the URL of the image $src = get_attachment_picture(); // if the url is not empty, display the image if(!empty($src)){ ?> <img src=”https://wordpress.stackexchange.com/questions/48896/<?php echo $src; … Read more

Where is this function’s callback getting its arguments from?

If you have a look at function do_meta_boxes() in wp-admin/includes/template.php then you’ll see this line close to the end of the function: call_user_func($box[‘callback’], $object, $box); That calls the callback function and provides the two arguments. The $box argument holds all the information about the metabox, like ID, title, callback function. In wp-admin/edit-form-advanced.php, which displays your … Read more

How to only publish posts with image in it

I found and modified a chunk of code found here: http://www.wprecipes.com/wordpress-tip-detect-if-a-post-has-at-least-one-image. <?php while ( have_posts() ) : the_post(); $content = $post->post_content; $searchimages=”~<img [^>]* />~”; preg_match_all( $searchimages, $content, $pics ); $iNumberOfPics = count($pics[0]); if ( $iNumberOfPics > 0 ) { //your loop content goes here } endwhile; ?> I think this just looks for images entered … Read more

Why can’t I call a (member) function from within a foreach?

You use $mediatags variable in global scope as array in your loop, and then try to use the same variable as object in your function. You override your global $mediatags variable in your loop. Try to use following code: foreach($new_name_for_mediatags_array as $mediatag){ $args=”media_tags=animals&numberposts=10&return_type=li&size=thumbnail”; $media_items = get_attachments_by_media_tags($args); echo $media_items; };

Replacing global wp_query

Firstly, I’d seriously consider opting for another plugin (it hasn’t been maintained in over 2 years), or making use of WP’s built-in paginate_links. But, in the quest to provide a solution, give this a go: function wp_page_numbers_custom( $wp_query, $start=””, $end = ” ) { $_backup = array( ‘wp_query’ => @ $GLOBALS[‘wp_query’], ‘max_page’ => @ $GLOBALS[‘max_page’], … Read more

Custom Query Not Paginating

You need to set paged or an offset in your query, otherwise you’re always fetching the same 48 posts. $page = (get_query_var(‘page’)) ? get_query_var(‘page’) : 1; $args = array( ‘paged’ => $page, ‘posts_per_page’ => ’48’, ‘cat’ => ‘4’, ‘meta_query’ => array( array( ‘key’ => ‘Country’, ‘value’ => $country_search_array, ‘compare’ => ‘IN’ ) ) ); $gallery_query … Read more

Adding class to last list item? Not WP generated

I can only see achieving this by first building an array, then looping over it – I can’t find anything in APC’s docs about checking if it’s the last iteration of the_repeater_field: $images = array(); while ( the_repeater_field( ‘homepage_service’ ) ) $images[] = get_sub_field( ‘service_image’ ); if ( $images ) { $image_last = array_pop( $images … Read more