Order categories by sum of custom fields

$terms = get_terms( array( ‘taxonomy’ => ‘category’, ‘hide_empty’ => false, ) ); $sort = array(); //loop to list through all category foreach ( $terms as $term ) { $id = $term->ID; $name = $term->name; $args = array( ‘post_type’ => ‘post’, ‘category’ => $name, ); $query = new WP_Query( $args ); $sum = 0; if ($query->have_posts() … Read more

Adding fields to attachment – only shows when inserting new attachments

Okay I think I have it, you need to add a matching filter to attachment_fields_to_save to save the new field (say as post meta to the attachment.) add_filter( ‘attachment_fields_to_save’, ‘save_some_custom_field’, 10, 2 ); function save_some_custom_field($post, $attachment) { $attachid = $post[‘ID’]; // yes this is actually an array here update_post_meta($attachid,’someCustom’,$attachment[‘someCustom’]); } Then you would add to … Read more

Metabox value for post loop?

Thanks guys.I did it with WP_Meta_Query (https://codex.wordpress.org/Class_Reference/WP_Meta_Query) Solution: <?php $query = new WP_Query( array( ‘meta_key’ => ‘j4cob_yaz_ayarlar_show_on_slider_’, ‘meta_value’ => ‘show-on-slider’, ‘posts_per_page’ => 6 ) ); ?> <?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?> . Loop . <?php endwhile; wp_reset_postdata(); else : ?> <p><?php _e( ‘Sorry, no posts matched your … Read more

Counting number of images from loop

You can get images with foreach loop but first you have to print_r($images) and then get the value of the array something like this $images[‘image’] or $images[‘src’] or $images[‘url’] etc. But first check is there any record where you are getting get_sub_field(‘image’) all images. <?php if ( $images = get_sub_field(‘image’) ) : print_r($images); foreach($images as … Read more

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