我将从这里开始,永远不要将原始变量传递给sql查询!除非您对可变内容有100%的控制权,即使这样,我仍然不会原始传递它
始终use prepare().
现在根据你的需要你需要做这样的事情
<?php
$paged = (get_query_var( \'paged\')) ? get_query_var(\'paged\') : 1;
$posts = new WP_Query([
\'post_type\' => \'post\',
\'posts_per_page\' => 1,
\'post_status\' => \'publish\',
\'meta_key\' => \'Mytitle\',
\'meta_value\' => $mytitle,
\'meta_compare\' => \'LIKE\',
\'paged\' => $paged
]);
?>
<ul>
<?php if ($posts->have_posts()) : while ($posts->have_posts()) : $posts->the_post(); ?>
<li><?php the_title(); ?></li>
<?php
endwhile; endif;
wp_reset_postdata();
?>
</ul>
<div class="pagination">
<?php
echo paginate_links([
\'base\' => str_replace(999999999, \'%#%\', esc_url(get_pagenum_link(999999999))),
\'total\' => $posts->max_num_pages,
\'current\' => max( 1, get_query_var(\'paged\')),
\'format\' => \'?paged=%#%\',
\'show_all\' => false,
\'type\' => \'plain\',
\'end_size\' => 2,
\'mid_size\' => 1,
\'prev_next\' => true,
\'prev_text\' => sprintf(\'<i></i> %1$s\', __(\'Newer Posts\', \'text-domain\')),
\'next_text\' => sprintf(\'%1$s <i></i>\', __(\'Older Posts\', \'text-domain\')),
\'add_args\' => false,
\'add_fragment\' => \'\',
]);
?>
</div>
这是一个非常原始的示例,因此您需要根据需要进行更改。
提供一些资源,以便更好地了解每件事的工作原理。
- WP_Query class
- Looping WP_Query
- Pagination with WP_Query WPSE
- Wordpress pagination codex