Articles of get posts

get_post orderby not working in plugin

Please take a look at the loops below, I’m having issues trying to order the attachment by title, name, and modified. <?php foreach ($instance[‘data’] as $id) : $args = array( ‘include’ => $id, ‘post_type’ => ‘attachment’, ‘posts_per_page’ => -1, ‘post_status’ => ‘any’, ‘orderby’ => ‘title’, ‘order’ => ‘DESC’, ); $data_attach = get_posts($args); foreach ($data_attach as […]

URL rewriting taxonomy term

I’m trying to find solution for the following hours now and i don’t know if this is applicable. I have 1 Custom Taxonomy “Years” for Post Type “Post (default)”. The taxonomy has 2 Terms: “2014” and “2015”. I have select some posts from category “news” to use the 2 different Taxonomy terms. This shows me […]

How to get custom post type title, excerpt, thumbnail and permalink by post ID?

I have to generate several “loops” to get the title, excerpt, thumbnail and permalink of a custom post type ‘charity’ by post ID, because I will have multiple posts (charities) I need to target with a special class (absolute-positioned map pointers). Can you help me adjust my code so I can get it to work? […]

Loop through incrementing custom fields

I created 4 custom fields for a specific page. Field type: Post Object (I grab thumbnails and titles from the posts) Field names: featured_content_1 featured_content_2 featured_content_3 featured_content_4 Right now I display the content in a list like this: <ul> <li> <?php $featuredContentPostID = get_field(‘featured_content_1’)->ID; $selectedFeaturedContent = get_post( $featuredContentPostID ); ?> <a href=”<?php echo esc_url( get_permalink($featuredContentPostID) […]

How to use get_posts() function in functions.php

I am trying to load posts with ajax. But I am not getting any content of the posts. I am not posting my javascript since it is pretty straight. Here is my code in inc/helper-functions.php which is included in main functions.php. function get_my_posts(){ $posts_per_page = $_POST[‘posts_per_page’]; $category = $_POST[‘category’]; $args = array( ‘posts_per_page’ => $posts_per_page, […]

Unable to render custom field after attempt to generate a list of recent post in page template

When I try to render a list of recent post type either by using WP functions or WP query, I’m not able to render the custom fields that I have to render bit after. The content of box with class feat-block ends up empty every time when using one of following commands: $recent_news_posts = wp_get_recent_posts($news_post_settings); […]

Order post by taxonomy

I am trying to write a get_posts() query to retrieve 7 posts per page. The retrieval of these posts are based on 3 different tags, “Featured”,”Highlighted”, and “News”. Now the “Featured” post take priority over all others, so if there are 7 Featured Posts then only those post should be displayed on the page. The […]

Display Recent Posts in BuddyPress Profile

This is the code I use to get recent WordPress posts. <h2>Recent Posts</h2> <ul> <?php $recent_posts = wp_get_recent_posts(); foreach( $recent_posts as $recent ){ echo ‘<li><a href=”‘ . get_permalink($recent[“ID”]) . ‘”>’ . $recent[“post_title”].'</a> </li> ‘; } ?> </ul> I display this code in BuddyPress Profile Page. So I need to modify this code to display only […]

How to get posts by category and by choosing a taxonomy term?

I’m new to WordPress and I’ve managed to build most of a full custom theme for wordpress on my own. But the tricky stuff is starting to show its tail, and I’ve spent the last days stuck on Taxonomies. I just managed to put a code for registering a custom Taxonomy to sort my articles […]

get_posts $args won't accept array as one of the criteria?

The goal is to list attachments underneath a WooCommerce product, using the tags from that product. Everything works fine if I manually enter the tags at ‘product_tag’, but when I try to use an array $producttags, why doesn’t it work? add_action( ‘woocommerce_after_single_product_summary’, ‘precon_drawing_attachments’ ); function precon_drawing_attachments() { $productterms = get_the_terms( $post->ID, ‘product_tag’ ); $producttags = […]