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 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘