wordpress - Pagination not working using a custom SQL query with a custom type -
i've been struggling problem 2 days now. i've read dozens of posts can't solution.
note: var names in spanish since spanish website.
i've created custom type named "promocion", when listing archives when try go page 2 404 error.
the structure i'd set following:
- domain.com/promocion/new-promocion -> works well
- domain.com/promociones -> list of promociones, works too
- domain.com/promociones/page/2 -> error 404 - not found
- name of archive file in template: archive-promocion.php
- name of single page view in template: single-promocion.php
wordpress version: 3.1
plugins:
- wp-page-navi
- posts 2 posts plugin (http://wordpress.org/extend/plugins/posts-to-posts/), used create relation between posts , promociones.
here's custom type created in functions.php
register_post_type('promocion', array( 'label' => 'promociones', 'description' => 'promociones', 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'capability_type' => 'post', 'hierarchical' => false, 'rewrite' => array('slug' => 'promocion'), 'query_var' => true, 'has_archive' => 'promociones', 'menu_position' => 4, 'supports' => array('title','editor',),'labels' => array ( 'name' => 'promociones', 'singular_name' => 'promocion', 'menu_name' => 'promociones', 'add_new' => 'añadir nueva', 'add_new_item' => 'añadir nueva', 'edit' => 'editar', 'edit_item' => 'editar promoción', 'new_item' => 'nueva promoción', 'view' => 'ver promoción', 'view_item' => 'ver promoción', 'search_items' => 'buscar promociones', 'not_found' => 'no se encontraron promociones', 'not_found_in_trash' => 'no se encontraron promociones en la papelera', 'parent' => 'parent promoción',),) ); function my_connection_types() { if ( !function_exists( 'p2p_register_connection_type' ) ) return; p2p_register_connection_type( array( 'from' => 'promocion', 'to' => 'post', 'reciprocal' => true ) ); } add_action( 'init', 'my_connection_types', 100 );
and here's beginning of archive page (archive-promocion.php) custom sql query , set pagination:
if ( $cat != '' ) { $cat_filter = 'wp_term_taxonomy.term_id = "' . $cat . '" and'; } else { $cat_filter = ''; } $querystr = ' select distinct promociones.id, promociones.post_title wp_terms inner join wp_term_taxonomy on wp_terms.term_id = wp_term_taxonomy.term_id inner join wp_term_relationships wpr on wpr.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id inner join wp_posts comercios on comercios.id = wpr.object_id inner join wp_p2p on wp_p2p.p2p_to = comercios.id inner join wp_posts promociones on promociones.id = wp_p2p.p2p_from wp_term_taxonomy.taxonomy = "category" , comercios.post_type = "post" , ' . $cat_filter . ' promociones.post_type = "promocion" order promociones.menu_order asc '; $totalposts = $wpdb->get_results($querystr, object); $ppp = 2; $wp_query->found_posts = count($totalposts); $wp_query->max_num_pages = ceil($wp_query->found_posts / $ppp); $on_page = intval(get_query_var('paged')); if($on_page == 0){ $on_page = 1; } $offset = ($on_page-1) * $ppp; $wp_query->request = $querystr . " limit $ppp offset $offset"; $pageposts = $wpdb->get_results($wp_query->request, object);
.htaccess file
<ifmodule mod_rewrite.c> rewriteengine on rewritebase /sitiodeloschicos/ rewriterule ^index\.php$ - [l] rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule . /sitiodeloschicos/index.php [l] </ifmodule>
please me, i'm going insane here , i'm late project. thanks!
well, after 1 week, yes, 1 week of pulling hair, reading every forum on internet , asking everybody, found solution, pretty dumb.
all code posted above working perfect, there's nothing wrong it.
what messing code had setup in admin panel display 10 posts per page. in code changed display 1 per page testing purposes, somehow wordpress still using 10 value configured in admin panel.
so did changed value 1 in admin panel, , increased mine in code. nasty solution works.
is there way setup global value of posts per page code?
Comments
Post a Comment