douyi5157 2018-01-18 17:33
浏览 25
已采纳

从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' ); 
  }
}
  • 写回答

1条回答 默认 最新

  • 普通网友 2018-01-24 16:54
    关注

    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
              }
            }
          }
        }
      }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀