Import Instagram post to WordPress blog post

I’m not currently aware of other ways rather then: Creating an Instagram App Get an access token Build a small API handler Something like this to put in your functions.php: function my_instagram() { $transient_key = ‘instagram_data’; $feed_data = get_transient( $transient_key ); if( false === $feed_data ) { $feed_data = json_decode(file_get_contents(‘https://api.instagram.com/v1/users/self/media/recent/?access_token=<ACCESS_TOKEN>&count=4’)); if ( is_array( $feed_data->data ) … Read more

wp_query get the 2nd post

I figured out you can use ‘offset’ => 1, to skip 1 post and get the 2nd. Change the number to however many posts you want to skip. ie. set it to 2 to get the 3rd. $loop = new WP_Query( [ ‘post_type’ => ‘product’, ‘posts_per_page’ => 1, ‘offset’ => 1, ‘meta_key’ => ‘total_sales’, ‘orderby’ … Read more

First x post with another template then the others

It shows more than 3 posts because you used post_per_page when it should be posts_per_page (note the plural “posts”). But actually, you can use the same query and use a counter to display the different template parts: $loop = new WP_Query( array( ‘post_type’ => ‘post’, ‘posts_per_page’ => 5, ) ); $c = 1; // post … Read more

Change date format

You will need to use strtotime() with Date() to make your own date format If you already know the meta key that you need you can do the following $post_meta_data = get_post_meta(get_the_ID(), ‘endDate’, true); See get_post_meta for more information about the function. Now that we have the value and going your format all you need … Read more

Woocommerce: Complex query in pre_get_posts [closed]

When I have complex querie to do, I often use a prequery to get the good post_ids. Then I pass this list of post_ids to my main query via the post__in parameter of WP_Query. $meta_key = ‘RepeaterName_%_FieldName’; $meta_value=”MyCustomValue”; global $wpdb; $post_ids = $wpdb->get_col( $wpdb->prepare( ” SELECT pm.post_id FROM $wpdb->postmeta pm WHERE pm.meta_key LIKE %s AND … Read more