WordPressでpaginate_links()を使用してユーザーディレクトリを開発しようとしています。以下は、正しく構築されたページリンクのURLで正しく設定されているようです(たとえば、リンク3は私にhttps://www.example.com/private-messaging/?pmaction=directory&p=3を与えます)。しかし、$ _GET ['p']はページ番号を取得していません。私が$ _SERVER ['QUERY_STRING']でそれをチェックすると、私はpmaction =ディレクトリを取得します。 print_r($ _ GET)でチェックすると、URLに関係なく1が返されます。 $ _GETからキーと値を抽出すると、キー= pmaction、値=ディレクトリが返されます。私は何が欠けているのか分かりません。 $ _GETは、同様のメソッドを使用してアプリケーション内の他の場所で正常に動作しますが、ここでは機能しません。私は何が間違っているかもしれませんか? https://www.example.com/private-messaging/?pmaction=directory&p=3
それは終わりを取り除き、ディスプレイのみ: https://www.example.com/private-messaging/?pmaction=directory
そして、私は、プロセスのステップ1で、午前私は手動で私のブラウザでこのURLを送信する場合
。私が手動で$ page = 3を設定した場合、私はステップ3(ステップ3のみ)を見ます。
function dispDirectory()
{
global $user_ID;
// Disallow directory if there is a messaging administrator and this person is not it.
if ($this->admin_user_id && $this->admin_user_id != $user_ID) {
return '';
}
$count_args = array(
'role' => 'Client',
'fields' => 'all_with_meta',
'number' => 999999
);
$user_count_query = new WP_User_Query($count_args);
$user_count = $user_count_query->get_results();
$total_users = $user_count ? count($user_count) : 1;
$page = isset($_GET['p']) ? $_GET['p'] : 1;
$users_per_page = 15;
$total_pages = 1;
$offset = $users_per_page * ($page - 1);
$total_pages = ceil($total_users/$users_per_page);
$directory = "<form name='form' method='post'><label for='clientname'>Client Name: </label>
<input name='clientname' id='clientname' type='text' style='width: 181px;'
value=''/><input type='submit'></form>";
$search_string = $_POST["clientname"];
if (!empty($search_string)) {
$args = array (
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'first_name',
'value' => $search_string,
'compare' => 'LIKE'
),
array(
'key' => 'last_name',
'value' => $search_string,
'compare' => 'LIKE'
)
)
);
}else{
$args = array (
'meta_key' => 'last_name',
// return all fields
'fields' => 'all_with_meta',
'number' => $users_per_page,
'offset' => $offset // skip the number of users that we have per page
);
}
$wp_user_query = new WP_User_Query($args);
$wp_user_query->query_orderby = str_replace('user_login', 'wp_usermeta.meta_value', $wp_user_query->query_orderby);
$wp_user_query->query();
$users = $wp_user_query->get_results();
if (!empty($users)) {
foreach($users as $u)
{
$firstName = get_user_meta($u->ID, 'first_name', true);
$lastName = get_user_meta($u->ID, 'last_name', true);
$directory .= '<p><strong>'.$lastName.', '.$firstName.'</strong> - <a href="'.$this->actionURL.'newmessage&to='.$u->ID.'">'.__('Send Message', 'cartpaujpm').'</a> <a href="'.$this->actionURL.'oldmessages&to='.$u->ID.'">'.__('Old Messages', 'cartpaujpm').'</a></p>';
}
} else {
$directory .= '<p><strong>No Clients Found</strong></p>';
}
$directory .= paginate_links(array(
'base' => get_pagenum_link(1) . '%_%', // the base URL, including query arg
'format' => '&p=%#%', // this defines the query parameter that will be used, in this case "p"
'prev_text' => __('« Previous'), // text for previous page
'next_text' => __('Next »'), // text for next page
'total' => $total_pages, // the total number of pages we have
'current' => $page, // the current page
'end_size' => 1,
'mid_size' => 5,
));
return $directory;
}
おかげで、「PAGENUM」から「P」から参照を変更してフォーマット」で(「PAGENUM」、「%の#%と」)add_query_argには「基本」プロパティを変更したものを、私はあなたの例から取りました''空白。それはうまくいった。私はCSSのオプションが好きですが、これはむしろ基本的なものです。どうもありがとうございました。それは素晴らしい実行しています。 –
あなたは歓迎です@CraigTucker – vel