how to upload image using wp_handle_upload

here’s my example of how to upload multiple images: add_action( ‘add_meta_boxes’, ‘my_test_metabox’ ); function my_test_metabox() { add_meta_box( ‘my_test_metabox’, ‘File upload’, ‘my_test_metabox_out’, ‘post’ ); } add_action(‘post_edit_form_tag’, ‘update_edit_form’ ); function update_edit_form() { echo ‘ enctype=”multipart/form-data”‘; } function my_test_metabox_out( $post ) { $files = get_post_meta( $post->ID, ‘my_files’, true ); if( ! empty( $files ) ) { echo ‘Files … Read more

Multiple Loops Homepage?

You can use current_post within the loop to track where you are and split the loop into multiple parts: while ( have_posts() ) : the_post(); // only output content if it’s post 1 – 5 if( 5 > $wp_query->current_post ): the_title(); else : break; endif; endwhile; // do another query/loop $custom_loop = new WP_Query( $args … Read more

Child Pages Loop

I’m fairly certain the problem is that some template tags rely on the global $post variable. Using setup_postdata() as you are now, will not alter $post. If you replace all the instances of $pageChild with $post, everything should work. However, I would strongly recommend using the WP_Query class and setting up your post data with … Read more

Pagination not working on home page

I had faced the same problem. And finally, I solved the problem. Getting the current Pagination Number <?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; ?> For getting the current pagination number on a static front page (Page template) you have to use the ‘page’ query variable. <?php $paged = (get_query_var(‘page’)) ? get_query_var(‘page’) : 1; … Read more

Get date of last update outside of loop

It is unclear if you are looking for the last updated post or for the last updated date for some particular post. The answer by @PatJ assumes the former. To do the latter: $qry = new WP_Query(array(‘p’=>1)); var_dump($qry->posts[0]->post_modified); Or… $date = $wpdb->get_var(“SELECT post_modified FROM {$wpdb->posts} WHERE ID = 1”); var_dump($date); Of course you need to … Read more

Insert image or ad script after 3 posts using the loop

instead of a post counter, you could use the variable $wp_query->current_post – which starts with 0 for the first post in the loop; for some output after the third post, use for instance this before the line with endwhile;: <?php if( $wp_query->current_post == 2 ) { ?> DO SOMETHING <?php } ?>

Cleanest Way to Select Every Second Element in a Loop?

I wouldn’t consider that strange :). WordPress uses a similar method to apply the ‘alternate’ class to every other row in the tables on the admin page, something like: <ul> <?php if (have_posts()) : while (have_posts()) : the_post(); ?> <?php $class = (empty($class) ? ‘class=”alternate”‘ : ”);?> <li <?php echo $class; ?> ><?php the_content(); ?></li> … Read more

Using the Loop to show all levels of subpages under a parent page? Halfway there

Sounds like you’re looking for a recursive function, ie a function that calls itself. Here’s a rough outline of how it can be done: function wpse13669_show_all_children( $post_id, $current_level ) { $children = get_posts( array( ‘post_type’ =>’page’, ‘posts_per_page’ =>-1, ‘post_parent’ => $post_id, ‘order_by’ => ‘title’, ‘order’ => ‘ASC’ ) ); if ( empty($children) ) return; echo … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)