첨부 파일의 목록을 단락 기호로 바꾼 단락 기호를 페이지 번호 매기기로 추가하는 기능을 만들려고합니다 ( ).WP_Query는 아무 것도 반환하지 않습니다.
문제는 WP_Query()가 아무 것도 반환하지 않는다는 것입니다.
함수 코드는 다음과 같습니다. 내 functions.php에 있는데, 내 content-page.php에서 호출됩니다.
$a = shortcode_atts(array('number' => '10'), $atts);
//Protect against arbitrary paged values
$paged = (get_query_var('paged')) ? absint(get_query_var('paged')) : 1;
$args = array(
'post_type' => 'attachment',
'post_parent' => get_the_ID(),
'posts_per_page' => $a['number'],
'paged' => $paged
);
$the_query = new WP_Query($args);
if ($the_query->have_posts()) :
while ($the_query->have_posts()) : $the_query->the_post();
the_title();
endwhile;
$big = 999999999; // need an unlikely integer
$retuen_string .= paginate_links(array(
'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
'format' => '?paged=%#%',
'current' => max(1, get_query_var('paged')),
'total' => $the_query->max_num_pages
));
wp_reset_postdata();
else :
_e('Sorry, no posts matched your criteria.');
endif;
그리고 print_r ($ the_query) 결과는 다음과 같습니다.
WP_Query Object (
[query_vars] => Array (
[post_type] => attachment
[post_parent] => 26
[posts_per_page] => 15
[paged] => 1
[error] =>
[m] =>
[p] => 0
[subpost] =>
[subpost_id] =>
[attachment] =>
[attachment_id] => 0
[name] =>
[static] =>
[pagename] =>
[page_id] => 0
[second] =>
[minute] =>
[hour] =>
[day] => 0
[monthnum] => 0
[year] => 0
[w] => 0
[category_name] =>
[tag] =>
[cat] =>
[tag_id] =>
[author] =>
[author_name] =>
[feed] =>
[tb] =>
[comments_popup] =>
[meta_key] =>
[meta_value] =>
[preview] =>
[s] =>
[sentence] =>
[fields] =>
[menu_order] =>
[category__in] => Array ()
[category__not_in] => Array ()
[category__and] => Array ()
[post__in] => Array ()
[post__not_in] => Array ()
[tag__in] => Array ()
[tag__not_in] => Array ()
[tag__and] => Array ()
[tag_slug__in] => Array ()
[tag_slug__and] => Array ()
[post_parent__in] => Array ()
[post_parent__not_in] => Array ()
[author__in] => Array ()
[author__not_in] => Array ()
[ignore_sticky_posts] =>
[suppress_filters] =>
[cache_results] => 1
[update_post_term_cache] => 1
[update_post_meta_cache] => 1
[nopaging] =>
[comments_per_page] => 50
[no_found_rows] =>
[order] => DESC
)
[tax_query] => WP_Tax_Query Object (
[queries] => Array ()
[relation] => AND
)
[meta_query] => WP_Meta_Query Object (
[queries] => Array ()
[relation] =>
)
[date_query] =>
[post_count] => 0
[current_post] => -1
[in_the_loop] =>
[comment_count] => 0
[current_comment] => -1
[found_posts] => 0
[max_num_pages] => 0
[max_num_comment_pages] => 0
[is_single] => [is_preview] =>
[is_page] =>
[is_archive] =>
[is_date] =>
[is_year] =>
[is_month] =>
[is_day] =>
[is_time] =>
[is_author] =>
[is_category] =>
[is_tag] =>
[is_tax] =>
[is_search] =>
[is_feed] =>
[is_comment_feed] =>
[is_trackback] =>
[is_home] => 1
[is_404] =>
[is_comments_popup] =>
[is_paged] =>
[is_admin] =>
[is_attachment] =>
[is_singular] =>
[is_robots] =>
[is_posts_page] =>
[is_post_type_archive] =>
[query_vars_hash] => ab31e2fb8fd323e014706374fb98b349
[query_vars_changed] =>
[thumbnails_cached] =>
[stopwords:WP_Query:private] =>
[query] => Array (
[post_type] => attachment
[post_parent] => 26
[posts_per_page] => 15
[paged] => 1
)
[request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_parent = 26 AND wp_posts.post_type = 'attachment' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') ORDER BY wp_posts.post_date DESC LIMIT 0, 15
[posts] => Array ()
)
아무도 도와 줄 수 있습니까?
작동하지 않지만 감사합니다. 포인트가 $ the_query를 비우고 쿼리 인수 'paged'를 추가합니까? –