Tag Info

New answers tagged

1

Use is_user_logged_in you code may like $posts_array = get_posts( array( 'post_type' => 'download', 'post_status' => 'publish' ) ); //$posts_array = apply_filters( 'downloads_shortcode', $posts_array ); foreach($posts_array as $post) { setup_postdata($post); if ( is_user_logged_in() ){ $title = "<a href=". get_permalink( $post->ID ) . ...


0

Your question is too broad. Break the question down into more specific questions. Then research those questions and bring the unanswered questions to us. For example, you might break this down into these specific questions. How do I: Add a menu item to the Dashboard? Create an admin options page form? Submit a custom admin page form? Page a custom option ...


2

query_posts() is a horrible function and shouldn't be used. Also it doesn't has much to do with loading template, since it was originally designed to be used in template. Should not be used. If you are looking for logic of how WP picks template files from theme to load see Template Hierarchy. If you just want to load some [part of] template manually, ...


-1

put this code within the loop in single custom post type $attachments = get_posts( array( 'post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order', 'order' => 'DESC', 'posts_per_page' => -1 ) ); if ( $attachments ) { ...


3

Template tag functions rely on global variables to access post being processed and retrieve data from it or related to it. Main variable of them is $post which holds post object itself. In your example it's not explicit, but what is happening is that your loop assigns data to $post, if name for iteration wasn't $post you would need to do that explicitly ...


1

The WordPress function get_posts() is making it's own instance of WP_Query that is not globally accessible: function get_posts($args = null) { // ... cut ... $get_posts = new WP_Query; return $get_posts->query($r); } so you could instead try $results = get_posts($args); echo count($results); to give you the array count of post objects ...


0

Solved it with: function myedit_posts_orderby($orderby_statement) { $orderby_statement = "wp_postmeta.meta_value+0 DESC, wp_posts.post_date DESC"; return $orderby_statement; } add_filter('posts_orderby', 'myedit_posts_orderby'); WP_Query... ...for some reason WP_Query only applied DESC order to date, and not to meta value.


0

$tax_query = array ( array ( 'taxonomy' => 'product_cat', 'field' => 'slug', 'terms' => $cat_name ) ); $args = array( 'tax_query' => $tax_query, 'numberposts' => -1); $lastposts = get_posts( $args );


2

The WordPress function get_posts() supports: 'posts_per_page' => 10, 'numberposts' => 10, so you should use: $projects = get_posts(array('post_type' => 'projects', 'numberposts' => 10)); instead of $projects = get_posts(array('post_type' => 'projects', 'number posts' => 10)); If you want to show all posts, you can use ...


-1

You can use the $args in get_children, but ensure you also specify the post ID that you want to retrieve children from, even if it is the current page children you want get_children( array( 'post_parent' => $post->ID, 'orderby' => 'menu_order', 'order' => 'ASC' ));


2

First, exclude the featured image (= post thumbnail) from the query, then set up the posts array as combination of the featured image and the other images. Put this directly below $args = ... and above $attachments = ...: if (has_post_thumbnail($post->ID)) { $featured_image = get_post_thumbnail_id($post->ID); $args['exclude'] = ...



Top 50 recent answers are included