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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!