Functions Error: Impacting Galleries

You can try to add the condition $query->is_main_query() in your if-sentences so it won’t affect the gallery queries: // Posts per page add_filter(‘parse_query’, ‘wpq_parse_query’); function wpq_parse_query($query) { if(!$query->is_main_query()) { return $query; } if($query->is_archive()) { $query->query_vars[‘posts_per_page’] = get_option(‘to_count_archives’, 1); } if($query->is_home()) { $query->query_vars[‘posts_per_page’] = get_option(‘to_count_home’, 1); } if($query->is_search()) { $query->query_vars[‘posts_per_page’] = get_option(‘to_count_search’, 1); } return $query; … Read more

Checking for ‘gallery’ shortcode using strpos always returns false

You will need global $post to get the $post variable into the scope of that function. function doraemon_scripts() { if( is_single() ) { global $post; if (strpos($post->post_content,'[gallery’) === false){ } else { // wp_enqueue_style( … ); // wp_enqueue_script( … ); } } } add_action( ‘wp_enqueue_scripts’, ‘doraemon_scripts’ ); Using the $post global outside of the Loop … Read more

Detecting if parent page has gallery

It happens because strpos returns 0 (zero index position) when gallery shortcode is at the start of the content which is treated as false by the if condition. Solution is to use Identical operator === in condition to check if the return value is a boolean false.

How to dynamically insert in the image caption?

That markup is created by the caption shortcode. If you look at the the source for that shortcode you will see this: // Allow plugins/themes to override the default caption template. $output = apply_filters(‘img_caption_shortcode’, ”, $attr, $content); if ( $output != ” ) return $output; That means that you can hook a function into img_caption_shortcode … Read more

How can I attach a gallery to a post with a short code?

The gallery is the shortcode. It is not, so far as I know, saved in any other place or in any other way than in that shortcode. You can print/process shortcodes anywhere you want with tricks like this: echo do_shortcode(”); Or this: $gallery_shortcode=”‘; print apply_filters( ‘the_content’, $gallery_shortcode ); Both from the Codex. You can see … Read more

Making a [gallery] in a loop with attachment IDs?

First get all of the feature thumbnail ids, and then populate the gallery. Code – <?php global $wpdb; $featured_ids = $wpdb->get_col(“SELECT meta_value FROM $wpdb->postmeta WHERE meta_key=’_thumbnail_id'”); $featured_ids = array_map(‘intval’, $featured_ids); $featured_ids = array_unique($featured_ids); echo do_shortcode(”); ?>

Get all image IDs from the Media Library

From my understanding I can’t get the image IDs directly from wordpress. I have to first get their URLs and then extract their IDs. If there is a more efficient way to do this please let me know. I’m not sure I follow you there, but did you try this: $ids = get_posts( array( ‘post_type’ … Read more

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