New answers tagged

2

As I far I know, get_posts() function can not be used to paginated results. It is intended to get an array of posts and it sets no_found_rows to true by default from WP 3.1. Pagination won't work unless you set it to false, or better, use WP_Query. numberposts is also a invalid argument. $paged = ( get_query_var( 'page' ) ) ? get_query_var( 'page' ) : 1; ...


0

So I finally figured it out. Using pre_get_posts and the $_GET global var to check if any query args have been added works a treat. I used the follow code to get the desired results. function my_pre_get_posts($query) { if( $query->is_main_query() && is_archive() && !isset($_GET['orderby']) && // ...


1

I use the following for multiple post types, just replace foo and bar with your own post types: $args = array( 'post_type' => array( 'foo', 'bar' ), 'orderby' => 'post_date', // other parameters as needed ); $q = new WP_Query( $args ); if ($q->have_posts()) : while ...


-2

You don't have any posts query running probably. Try this (added query_posts();) <?php get_header(); ?> <div class="left"> <?php query_posts( $args ); if ( have_posts() ) : // Start the loop. while ( have_posts() ) : the_post(); //echo for debugging echo 'index<br>'; echo ...


-1

maybe try <?php instead of <? in your lines of code, not sure but I understand that this can cause problems. or use <?php echo $post->post_content; ?> and try without 'Read More' means only <?php the_content(); ?>


1

echo $post->post_content; will echo your post content. Keep in mind though, it's raw out of the database (same as get_the_content()). If you want to apply the same filters that the_content() receives, follow the instructions in the codex: <?php $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); ...


1

Try this, home it will work properly. just replace 'taxonomy' with your taxonomy and post type in wp_query. <?php $categories = get_terms('taxonomy', array('orderby'=>'name','hide_empty' => 0)); foreach( $categories as $category){ $category_link = get_category_link($category->ID); $args = array('post_type' => 'post', ...


1

This will display the title of the page when a static page is set to show posts. e.g. I show posts on my homepage... It'll do nothing. If I, say, show posts on page titled News... It'll show News in H1 This is used so that title of the page is shown, whenever posts are shown on a page but nothing when blog posts are shown on front page (home page). We ...


1

I am not sure about "popular", it doesn't seem so to me (but then I don't look at that many themes). You seem to grasp fine what each conditional does, so this shouldn't be confusing to you. This combines conditions to check that blog index is being displayed and it's not at the front page. Ah, the reason for single_post_title() I would guess is that it ...


0

You can simply call get_the_content(postId) <?php echo get_the_content($postId); ?>


1

I think you need to do something like this: <?php $args = array( 'post_type' => 'shop', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array( 'relation' => 'AND', array( 'key' => 'cu_status', 'value' => array( ...


0

Based on the codex, the meta_query parameter contains one or more array with the relation parameter not set if single inner meta_query array. Also remove the page parameter as it serves only for a Static Front Page. Your args array should look like that: $archive_args = array( 'post_type' => 'speight_home_plans', 'orderby'=> 'title', ...


0

This is more of a logical problem. Lets say you stored location (City/address/Lat-long(Best would be Lat/long) of user in a custom field (There should be a standard way to assign locations to users throughout the site). you want to query posts from users which are near this particular user. Get custom field value of location for this user. Convert this ...


1

You can try this by using meta query to filter results and then adding orderby to order results. Below arguments should work $args = array( 'post_type' => array('post', 'video'), 'meta_key' => 'pp_like_count', 'orderby' => 'meta_value_num', "meta_query" => array( array( "key" => "pp_lang", ...


0

You can use meta query see below link it will help you. How to order by meta field


0

What is wrong here is your assumptions that the values should be the same. I don't know of the top of my head what exactly the term count represent, and it is not apparent from the docs, but it is most likely a raw number of posts associated with the term. OTOH wp_query (which is used for the main loop) takes into account user permissions on top of that raw ...


0

Thank You very much. Problem solved. Here is my code. <section id="features"> <div class="container"> <div class="row"> <?php $args = array( 'post_type' => 'service', 'posts_per_page' => 4 ); $service = new WP_Query($args); while ( $service->have_posts() ) : ...


1

The PHP modulus operator gives you the remainder from dividing 2 numbers. The remainder from the division of any number by two is either 0 or 1, so we can use that to provide an "alternator". We use the current_post var as a counter, which is available in any WP_Query object: while( have_posts() ){ the_post(); if( $wp_query->current_post % 2 ){ ...


2

If I understood this issue correctly the problem with your current code is that you are incrementing $totalPosts variable inside the while loop, so the variable gets incremented after every post thus resulting in the running order you described. To get the amount of posts returned matching the query, use $loop->found_posts (in this case) More ...


0

I would try it this way. Use a meta query to get your events list and load everything into a datatable. This seems like a perfect time to let visitiors filter and sort. Here's a simple implementtation (which may need tweaking). Just print or return the '$disp_data' variable from function call or in a template. If you don't have datatable set up I can help ...


1

Your best bet is not to run a bunch of queries but to loop through your data once to organize it then a second time to display it. Below is the logic you need. The exact code will depend on your data set. $events = array(); $posts = WP_Query( $args ); foreach ( $posts as $post ) { $venue = $post->venue; $day_of_month = date( 'd', $post->date ); ...


0

The problem is that whenever you call flag_it() there's no $flag available, so it's always going to result in "flag worked". Try using a static variable instead: function flag_it() { static $flag; if ( isset( $flag ) ) return; $flag = true; echo 'Flag worked!'; } Note that no matter how many times you call this function in a run, ...


-1

try this code just change category name <?php $args = array( 'post_type'=> 'post', 'category_name' => 'blog', 'orderby' => 'post_date', //'posts_per_page'=>'1' 'paged' => get_query_var('paged') ); query_posts( $args ); ...


0

Modify main query on post type archive page Instead of direct modify main query, just use normal loop ( you can create post type template, in your case archive-portofolio.php ), and run your modifying query under filter pre_get_posts. Your normal loop on archive-portfolio.php <div class="row text-center small-up-1 medium-up-2 large-up-3 ...


0

It's a little too much code to put here but here's how you do it. There are a lot of good tutorials (and plugins) on that site. This is the best example I've seen for managing the quick edit screen. Since the quick edit screen is related to the columns displayed you may need to manually control the columns in the screen as well. To do that use the ...


0

Found the issue. It had to do with one of my post being sticky. Found the answer here.



Top 50 recent answers are included