从phpmyAdmin Wordpress获取一系列项目

In my phpAdmin I have a list of arrays that I need to be able to access in php Wordpress.

I need to get these two arrays and the variables associated with them but I can't find anywhere how to access this type of information.

Essentially I would like to loop through all these items and match one of their variables with the ID of specific posts - I have the post part.

wp_learnpress_sections
wp_learnpress_section_items

Basically the item_type is an lp_lesson which is a custom post type. I am able to grab all the posts from wp_posts so I figured I would be able to grab these other arrays?

Edit:

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

My theme function. This works for all the posts. However, I want to be able to find out which section_id a post belongs to.

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' ); 
  }
}
doubi2228
doubi2228 我很抱歉。我添加了更多关于我想要完成的信息(如果可能的话)。
接近 3 年之前 回复
dsfgds4215
dsfgds4215 显示所有信息,这可能有所帮助。你如何在数据库中保存这些数组?表的结构是什么,你在哪里服务数组?你在哪里定义了与它们相关的变量?你想在哪里访问(从哪个文件)到那个数组?
接近 3 年之前 回复
douzuqin3467
douzuqin3467 PhpMyAdmin用于管理您的数据库-而不是PHP数组或任何类型。
接近 3 年之前 回复

1个回答

Full function that does it:

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
          }
        }
      }
    }
  }
}
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐