wordpress,pagination,custom-post-type , Custom Loop Pagination in Wordpress


Custom Loop Pagination in Wordpress

Question:

Tag: wordpress,pagination,custom-post-type

im using this custom loop within a wordpress page. It works great (although it has been simplified here). However, it displays 100's of search results on one page. Because it is a custom loop, i am struggling to get it to work with some pagination (ideally 10 per page). Has anyone achieved this before and willing to point me in the right direction?

Many thanks ...

    <ul id="property-holder">
    <?php if ( $location_query->have_posts() ) :
    $row_counter = 0;

    while ( $location_query->have_posts() ) :
    $location_query->the_post();

    $date = get_field("availdate");
    $date = str_replace('/', '-', $date);
    $date = date('Y-m-d', strtotime($date));

    if ($date > $future) {
    $row_counter += 1;

    echo '<li id="property-item">';
    echo '<p>' . 'Test' . '</p>';
    echo '</li>';

    } 

    endwhile;

    else :

    echo 'No Results';
    endif; wp_reset_postdata(); ?>

    </ul>

    <nav>
    <?php previous_posts_link('&laquo; Previous 10 Results') ?>
    <?php next_posts_link('Next 10 Results &raquo;') ?>
    </nav>

Answer:

I am assuming you've definded $location_query like this $location_query = new WP_Query($args);, now in your args add posts_per_page => 10. This will split your results in 10 items per page. If your pagination doesn't show new items on the next page make your query like this:

$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
    'post_type' => 'your post type',
    'posts_per_page' => 10,
    'paged' => $paged
);
$location_query = new WP_Query($args);

Related:


Flask: [405 error] with pagination and POST request


python,flask,pagination
I have a Flask app with a route that uses pagination and has to handle GET and POST requests. I defined two routes for my function as described here to get the pagination working. When I post a form on a page other than the first then I get a...

Run AJAX function on form submit button after javascript confirm() cancel


javascript,jquery,ajax,wordpress,forms
I have a form where and AJAX function runs on form submission to make sure that the data in the form doesn't conflict with data in the database. If a conflict is found, the AJAX function pops up a confirm() box. If the user clicks "OK", the form is submitted....

Changing font-size of
  • on wordpress

  • css,wordpress,html-lists
    I am adding some pages on a wordpress themed website. There is a table with 3 columns: 1st column will be the title (larger font). Since it looks better and editing is easier, I started using <ul> instead of <td> Even though it works fine on JSFIDDLE font-size on the...

    How to crop image from center using wp_image_editor


    wordpress,image,wordpress-plugin,resize-crop,wp-image-editor
    I am working on WordPress plugin. In plugin the user upload images from meta field and in back end i use wp_image_editor for cropping and re sizing the images. The images re sized very well but on cropping the images not cropped very well. I give x-dimension 100 and y-dimension...

    When I click to the next page on pagination,it goes to 404 error in codeigniter


    php,codeigniter,pagination
    In my News.phpcontroller,i'm having the below code: public function index() { $data['title'] = 'Database Details'; $config = array(); $config['base_url'] = base_url("news/index"); $config['total_rows'] = $this->news_model->record_count(); $config['per_page'] = 5; $config['uri_segment'] = 3; //$config['use_page_numbers'] = TRUE; // $config['page_query_string'] = TRUE; $choice = $config["total_rows"] / $config["per_page"]; $config["num_links"] = round($choice); $this->pagination->initialize($config); $page =...

    If image is null from JSON, use another image - AngularJS


    json,angularjs,wordpress,angularjs-ng-repeat,wp-api
    Below I have an ng-repeat where the inner div gets a background image set after reading a JSON file. My question is - If post.featured_image.attachment_meta.sizes.medium.url does not exist or is null, what would be the best approach to replace this with another image? Say a default backup image? A solution...

    Laravel 5 pagination with trailing slash redirect to 301


    php,laravel,redirect,pagination,laravel-5
    I'm using Laravel 5 and notice that the pagination is adding a trailing slash before the ?page=# and with that, it always redirect to a 301 page. http://example.com/news/articles/?page=2 will do a 301 redirect to http://example.com/news/articles?page=2 This is causing my pagination using ajax to slow down because it is having 2...

    How to display grouped products in a list with quantity in woocommerce?


    wordpress,woocommerce
    I want to change the way grouped products are shown by two different versions of wordpress. case 1: Wordpress 4.1.5 running WooCommerce 2.3.11 with custom theme. case 2: Wordpress 4.2.2 running WooCommerce 2.3.11 with default theme. I need to display grouped products (child products) in a tabular form with quantity...

    WordPress expanding grid with thumbnail


    javascript,css,wordpress,grid,expand
    I'm using codrops solution to display team members in an expanding grid: http://tympanus.net/codrops/2013/03/19/thumbnail-grid-with-expanding-preview/ I was already able to change some code to display my post thumbnail in the grid preview. However, I want to display the same picture in full size in the expanded view. In the original version it...

    wp_schedule_event hook sheduled but not working


    php,wordpress,cron,wordpress-plugin,cron-task
    I'm trying to trigger cron job from WordPress Plugin that I'm writing (It's gonna take all new Products and export them to CSV every day) so the problem is that when I'm put this code in functions.php all working great and the code is valid but from the plugin folder...

    Trying to fill a SVG map from wordpress custom categories


    wordpress,dictionary,svg
    I've created a custom post_type (destinations) with a category (locations) to provide a tree structure for my SVG map: Continent/Country/Town Example locations: Europe/Germany/Berlin/POST Europe/Italiy/Sicily/POST North-Africa/Morocco/Marrakech/POST My plan was to fill the map by the country short codes like (DE for Germany, IT for Italia, LY for Libya (...). Here is...

    Woocommerce Return False with message


    php,wordpress,woocommerce
    I am using a function to remove the ability to purchase a product if its price is equal to, or greater than £50,000. I would like to add a message where the add to cart button usually is, to say "this product is over £50,000 - please contact us" add_filter(...

    How to fetch the page id and use it for an image name


    php,wordpress
    I am new in php. I want to make a condition for showing page id and set my image name is pageId and show this background image in my header banner. How to fetch page id use it fetching image for my banner background img. Here is my code: <div...

    woocommerce - make order notes required


    wordpress,woocommerce
    is it posible to make woo 'order_comments' field required - and show message If the field is not filled I have tried the following code but I can not get it to work. add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process'); function my_custom_checkout_field_process() { // Check if set, if its not set add an error. if...

    Can not link the author


    wordpress
    I am Making a blog site. I want to show all posts of a user by linking with his/her user name. But it's not working. My code is by <a href="<?php get_author_posts_url(get_the_author_meta('ID'));?>"><?php the_author();?></a> What's wrong with it actually?...

    CSS mystery: why the extra height in my div's?


    javascript,css,wordpress
    I'm just starting in on a new site and am getting extra space at the top of the div's I'm building for the home page. Using Safari's Web Inspector, I've eliminated any obvious padding or margins being responsible; but it's also seemingly telling me that the height of the div's...

    How to add stripslashes to get_option()


    regex,wordpress,wordpress-theming,sublimetext,stripslashes
    Hy, I created a WordPress Theme using a lot of custom options. While saving the options in the backend amongst other things I'm adding backslashes before characters that need to be escaped. Such as ' and ". Now I need to remove them before displaying them on the frontend. The...

    Wordpress function to effect only one (custom) post type, and not every post


    wordpress,custom-post-type
    I'm having an issue with a custom post type (WP Job Manager). I am using the following code in my functions file to 'add a default image to posts that have no image attached'. function custom_default_cover_image( $image, $args ) { global $post; if ( $image ) { return $image; }...

    How to call posts from PHP


    php,wordpress,caching,cron,call
    I have a website, that uses WP Super Cache plugin. I need to recycle cache once a day and then I need to call 5 posts (URL adresses) so WP Super Cache put these posts into cache again (caching is quite time consuming so I'd like to have it precached...

    Two language site in wordpress what i can do [on hold]


    wordpress
    I want to create 2 language site in word press. I am pretty new in word press. so what can i do. I will have 2 different theme for each language or do something else. The English is for left to right while Arabic is for right to left. So...

    need wordpress plugin to show 3 type of different kind of text, image and 2 buttons


    wordpress,plugins,wordpress-plugin
    I have slider image on http://techturners.com/arman-badwal/ page in "featured work" section. I need plugin to create dynamic slider like image in section.I use many sliders like cyclone-slider but they show only title, description and image.

    Wordpress Custom Post type archive display


    wordpress,templates,custom-post-type,advanced-custom-fields
    I have a custom post type named STORIES. Within that post type, I have categories, so each STORY is also assigned a category like this... Story 1 (assigned category RED) Story 2 (assigned category BLUE) Story 3 (assigned category GREEN) etc. I need to display a page which lists the...

    Bxslider, Custom Fields & Wordpress


    php,wordpress,bxslider
    Good Afternoon, can anyone explain how i can achieve two things with the existing code below: Remove the null values, as these are exporting bxslider items that have broken links For some reason two versions of each image in the the pager are showing. Can anyone see why and how...

    Wordpress End If Statements


    php,wordpress,woocommerce
    Apologies, PHP is not my strongest area so this might seem super easy to others. I am trying to implement a statement to say, when there is something in my WooCommerce Cart to show the cart. If there's nothing in the cart then show nothing. The code I have so...

    WooCommerce seems to only orderby date and not price


    php,ajax,wordpress,woocommerce
    I am loading in variable products via a custom WP_Query $args = array( 'post_type' => 'product', 'posts_per_page' => 100, 'product_cat' => 'beast-balls', 'orderby' => 'date', 'order' => 'desc' ); $loop = new WP_Query( $args ); if ( $loop->have_posts() ) { while ( $loop->have_posts() ) : $loop->the_post(); ?> <div class="product-node cat-beast-balls">...

    Woocommece login URL


    wordpress,woocommerce
    I have a custom page for login in Wordpress with Woocommerce integrated, and need that when a user click on my-account page, instead of using the login form from woocommerce, redirect to my custom login url. my-account page only must be seen in case the user is logged in,else, I...

    How to use curl return value in php script


    php,wordpress,curl,login
    I have two servers: A where WP is installed on one, and B where it's not. Application run on B is trying to use WP credentials for login. I have a login form on server B: <h1>Login</h1> <div> <form class="forma" id="form" action="login.php" method="POST"> <div class="form-group"> <label>Username</label> <input class="form-control" type="text" name="username"...

    String indices must be integers, new to python


    python,wordpress
    I hope I won't get trashed for this question. This is my first day with Python and all I've done so far is copy pasting and deducing from other snippets of code. I have no experience with code. I'm trying my hardest however this one I can't get past for...

    BeautifulSoup: Parsing bad Wordpress HTML


    python,html,regex,wordpress,beautifulsoup
    So I need to scrape some a site using Python but the problem is that the markup is random, unstructured, and proving hard to work with. For example <p style='font-size: 24px;'> <strong>Title A</strong> </p> <p> <strong> First Subtitle of Title A </strong> "Text for first subtitle" </p> Then it will...

    Wordpress log out using URL and redirect to specify page


    javascript,php,wordpress
    I have one Wordpress installation . i need to log out the user without any indication user is coming from particular URL.Is it possible? My code: <?php if($_GET['logout'] == 1) { $redirect_to = current_page_url(); ?> <script> window.location.href="<?php echo wp_logout_url( $redirect_to ); ?>"; </script> <?php } ?> I am using above...

    Text-decoration/CSS causing text to move


    html,css,wordpress
    I've tried a bunch of techniques to solve this. I've used float (left/right) and played with positioning (absolute & relative). None worked. Basically my navigation keeps moving when the the text decoration (font-weight: bold; in this case) is applied. I'm new to CSS and this is my first header- so...

    How can I implement this twbs-pagination


    javascript,php,jquery,pagination
    I am using this plugin to paginate my list items but I am confused about how to implement this to query to my table to pull and limit 10 or depending on my needs and display this inside in my <ul> tag. Here is my sample. Database.php class Database{ protected...

    Creating complex queries with WP_Query in Wordpress


    wordpress,wp-query
    Here's a complex query which we've built using WP_Query. It should: Ignore post id 191 AND Select all posts with 'reihenfolge' <= 18 AND Ignore posts without a featured image AND Order them randomly Here is the code: $args_projekte = array( 'post_type' => 'projekt', 'posts_per_page' => 18, 'meta_query' => array('relation'...

    Foundation and Wordpress blank spaces


    wordpress,zurb-foundation
    Anyone has an idea about the blank spaces that I'm getting in a while loop with wordpress using foundation framework? <div class="large-8 columns"> <?php query_posts(array('category_name' => 'revista', 'paged' => get_query_var('paged'), 'posts_per_page' => 9 )); ?> <?php while ( have_posts() ) : the_post(); ?> <article class="boletin large-4 columns" style="min-height:1px;"> <a href="<?php...

    ACF Multiple Map Markers


    wordpress,google-maps,google-maps-api-3,acf
    I'm using Advanced Custom Fields and want to pull in the field called 'location' to display some locations on a map. How would i adjust the following code to display multiple markers from my location field? The format of the custom field is like so: echo 'Location: ' . get_field('location');...

    WooCommerce: How to display Category Name in single-product.php


    php,wordpress,woocommerce
    How can I display the category name in single-product.php? In archive-product.php the code is: <?php woocommerce_page_title(); ?> but what could I use to show the category name in the single-product.php that belong to the category?...

    Excluding certain pages from being redirected to https


    wordpress,.htaccess,redirect,https,http-redirect
    I'm using the following rules on my WordPress website to: Redirect all http pages to https Redirect the careers page to http <IfModule mod_rewrite.c> RewriteEngine On # Go to https if not on careers RewriteCond %{SERVER_PORT} 80 RewriteCond %{REQUEST_URI} !^/careers$ [NC] RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R,L] # Go to http if...

    How to enable mod_rewrite on Apache 2.4?


    php,wordpress,apache,mod-rewrite,centos7
    I'm using Wordpress and wanted to enable pretty urls feature, but they don't work, i'm thinking that it's because of mod_rewrite, but i don't know how to enable it on Apache 2.4 under CentOS 7... I've already try this: grep -i LoadModule /etc/httpd/conf/httpd.conf | grep rewrite but nothing... Also would...

    How To check Product Have Variation in woocommerce


    php,wordpress,woocommerce,product
    Is there any way to check the product has variation something like Please help me. <?php If (product has variation) { echo"This Product have Variations "; } else { echo "This Product does not have Variations "; } ?> ...

    Wordpress page can't continue due to this error


    php,css,wordpress,wordpress-plugin,wordpress-theming
    I just faced this problem recently, I don't what causes it . But I need help fixing it. The error are : http://www.udesign.my/aaf4/wp-admin/admin-ajax.php?action=woocommerce_checkout Failed to load resource: the server responded with a status of 500 (Internal Server Error) http://fonts.googleapis.com/css?family=century+gothic+:300,400 Failed to load resource: the server responded with a status of...

    Slider misbehaving


    css,wordpress,wordpress-plugin-dev
    I've implemented a slider plugin into my theme and unfortunately, some misbevahiour occurs when is activated using the golden info+ button. The highlighted elements, is acting unusual: -the left sidebar text and the lower right arrow, is changing its position going up or disappearing (depending on slider); -the header logotext...

    CSS disable horizontaly scrolling - Wordpress [on hold]


    php,html,css,wordpress,responsive-design
    Hi im working on a wordpress blog and have the following problem: http://www.catlovers.co/17-cat-reactions-that-sum-up-your-love-life/ If i resize the browser (X-Axies) to a minimum like surfing on a mobile device i am able to scroll to the right in the Contend section (hold down middle mouse button). How can i change my...

    How to get range of 10 items from the arraylist in java? [on hold]


    java,arrays,arraylist,pagination
    I have a dynamic arraylist where the values are coming from the database. Let's say 85 records are selected from the database and inserted in to the database. Now I need to display those records in a pagination format with limit of 10 rows per page. How can I fetch...

    login with username or email in wordpress


    wordpress
    I am working on login template...but I want to make login with username as well as email.I got code with for that but it is not worked,it is as follow: function login_with_email_address($username) { $user = get_user_by('email',$username); if(!empty($user->user_login)) $username = $user->user_login; return $username; } add_action('wp_authenticate','login_with_email_address',10,1); I already put action in 'authenticate'...

    How can I change link in my dropdown menu [closed]


    php,wordpress
    How can I change links in my dropdown menu in worpress. Menu looks like this ITEM 1 || ITEM 2 || ITEM 3 || ITEM 4 || ITEM 2.1|| || ITEM 4.1|| || ITEM 2.2|| || ITEM 4.1|| || ITEM 2.3|| || ITEM 4.1|| I want that when the user...

    Random opening tabs/pills - bootstrap 3


    javascript,css,wordpress,twitter-bootstrap-3
    i want to open on every new site load another random tab with content. i think i have to do it with some java script but it don´t work. You can look at the page here: LINK Thanks for helping....

    Add second single product page in Woocommerce


    wordpress,woocommerce
    Is it possible to add a second single product page in Woocommerce? So basically when I am at the single product page I click the "next" button and I get directed to the same single product page with another template. So I just want to retrieve the same data on...

    How to exclude posts without featured images from custom post type WP_Query


    wordpress,wp-query
    We have the following WP_Query which collects all custom posts (except id=191) and lists them randomly: $args_projekte = array( 'post_type' => 'projekt', 'posts_per_page' => 18, 'post__not_in' => array(191), 'orderby' => 'rand', ); $query_projekte = new WP_Query($args_projekte); How do we extend this to ALSO exclude all posts WITHOUT featured images? Thanks...

    Coding after Wordpress loop not showing


    php,wordpress
    I have been working on a custom archive page but I have run into some trouble. The pagination is shifting down into the footer area. I have gone through my code several times and I cannot work out why this is happening. If I remove the loop, the template works...

    Wordpress Custom Post Type categroies


    wordpress,custom-post-type,advanced-custom-fields
    I have a custom post type called STORIES. When a user adds a new STORY, I need them to be able to assign a category (or multiple categories) to the post so I can sort them later by category. To do this, I only want specific categories I assign to...