从phpAdmin Wordpress获取一系列项目

时间:2018-01-18 17:33:40

标签: php wordpress phpmyadmin

在我的phpAdmin中,我有一个数组列表,我需要能够在php Wordpress中访问。

我需要获取这两个数组以及与它们相关的变量,但我无法在任何地方找到如何访问此类信息。

基本上我想循环遍历所有这些项目并将其中一个变量与特定帖子的ID相匹配 - 我有帖子部分。

wp_learnpress_sections
wp_learnpress_section_items

基本上,item_type是lp_lesson,这是一种自定义帖子类型。我能够从wp_posts中获取所有帖子,所以我想我能够抓住这些其他数组吗?

编辑:

This is the items (minus the sessions) that are displayed on the side panel along with wp_post.

Variables I need to access in my theme function from wp_learnpress_sections

Variables I need to access from wp_learnpress_section_items

我的主题功能。这适用于所有帖子。但是,我希望能够找出帖子属于哪个section_id。

add_action( 'wp_enqueue_scripts', 'win_9388244_format_lp_lesson' );

function win_9388244_format_lp_lesson() {
  //Get post type of lp_lesson
        $args = array(
         'post_type' => 'lp_lesson',
         'numberposts' => 99999
        );
        $posts = get_posts($args);
  foreach($posts as $post) {
    update_post_meta( $post->ID, 'wpk_icon_text', 'Test' ); 
  }
}

1 个答案:

答案 0 :(得分:1)

完成它的全部功能:

function win_9388244_format_lp_lesson() {
  //Get post type of lp_lesson
  $args = array(
    'post_type' => 'lp_lesson',
    'numberposts' => 99999
  );
  $posts = get_posts($args);
  global $wpdb;
  $sections = $wpdb->get_results( "SELECT section_item_id, section_id, item_id FROM wp_learnpress_section_items", ARRAY_A );
  $items = $wpdb->get_results( "SELECT section_course_id, section_id FROM wp_learnpress_sections", ARRAY_A );
  foreach($posts as $post) {
    $lesson_id = $post->ID;
    foreach($sections as $section) {
      if($section['item_id'] == $lesson_id) {
        $currentSection = $section['section_id'];
        foreach($items as $item) {
          if ($item['section_id'] == $currentSection) {
            $course = $item['section_course_id'];
            //switch $course with predefined variables for courses
          }
        }
      }
    }
  }
}