shortcode // get posts by ids

If you have no problem with using this shortcode [posts id=”1,2,3,4″], the only thing left for you to do is create an array from the id attribute and loop it, like this. add_shortcode( ‘posts’, ‘posts_shortcode’ ); function posts_shortcode($atts) { $atts = shortcode_atts( array( ‘id’ => ” ), $atts ); $HTML = ‘<div class=”posts”>’; foreach (explode(‘,’, … Read more

Attempting to list all product categories and the price range of all products within them

You can get using SQL query – global $wpdb; $results = $wpdb->get_col( ” SELECT pm.meta_value FROM {$wpdb->prefix}term_relationships as t INNER JOIN {$wpdb->prefix}term_taxonomy as tt ON tr.term_taxonomy_id = tt.term_taxonomy_id INNER JOIN {$wpdb->prefix}terms as t ON tr.term_taxonomy_id = t.term_id INNER JOIN {$wpdb->prefix}postmeta as pm ON tr.object_id = pm.post_id WHERE tt.taxonomy LIKE ‘product_cat’ AND t.term_id = {$term->term_id} AND … Read more

Retrieve alt text by referencing the img src

Did you get anywhere with this? I’ve just written a plugin that does exactly this job. It’s basically a cron job that scans all your posts & pages to create an internal index of which images are where. It then synchronises your Media Library alt text with the images in your content. It’s based on … Read more

Allow a user or role to view drafts and previews, but not other admin privileges?

Figured out an easier way. I gave them the edit_other_posts and edit_other_pages role capabilities, and then blocked their access to the admin area using the following: add_action( ‘init’, ‘eri_block_nonadmins_init’ ); function eri_block_nonadmins_init() { $current_url = eri_get_current_url( true, false); if ( (!current_user_can( ‘administrator’ ) && !( defined( ‘DOING_AJAX’ ) && DOING_AJAX )) && (is_admin() || $current_url … Read more