Php 通过slug或title wordpress获取页面内容

Php 通过slug或title wordpress获取页面内容,php,wordpress,Php,Wordpress,我正在创建一个博客,我在wordpress中的页面有困难,在我的情况下,我想在人们浏览博客时,在modal系统中随机插入两个页面的内容(原始内容) 示例: 当前页面>模式框>第01页内容或第02页内容 我知道通过页面id是可能的,但我想通过按段塞或标题获取页面内容,使其更具动态性 这是密码 <?php $term = get_taxonomy( $slug ); $args = array( 'post_type' => 'page', 'posts_

我正在创建一个博客,我在wordpress中的页面有困难,在我的情况下,我想在人们浏览博客时,在modal系统中随机插入两个页面的内容(原始内容)

示例: 当前页面>模式框>第01页内容或第02页内容

我知道通过页面id是可能的,但我想通过按段塞或标题获取页面内容,使其更具动态性

这是密码

<?php

  $term = get_taxonomy( $slug );

  $args = array( 
    'post_type' => 'page', 
    'posts_per_page' => 1, 
    'orderby' => 'RAND',
    'tax_query' => array( array(
        'taxonomy' => $term,
        'field' => 'slug',
        'terms' => array('page-01', 'page-02'),
    ) )
  );

  $rand = new WP_Query($args);

  if ($rand->have_posts()) {
    while ($rand->have_posts()) {
      $rand->the_post();
      the_content();
    }
  }
?>


我知道从查询中删除分类法会获取发布页面的内容,但在我的情况下,我需要从两个特定页面获取内容

您可以使用
post\u name\u in
按多个slug进行过滤,例如:

  $args = array( 
    'post_name__in' => array('page-slug-1', 'page-slug-2'),
    'post_type' => 'page', 
    'posts_per_page' => 1, 
    'orderby' => 'RAND',
  );

您可以在上找到更多详细信息。

好先生,谢谢您的回答,这让我很高兴,谢谢您的回复。