• Resolved Xaib Aslam

    (@lahorimela)


    Hello,

    I create a custom post type and I did what I want, now need more things to do.

    My Custom Table: https://ibb.co/N69GFC0

    In this table you can see ID, these are wordpress post id’s.

    I create a Post (100 PKR) and create sub posts under (100 PKR) with date wise (15-12-2022, 15-09-2022, 15-06-2022, 15-03-2022) and I am fetching data from the database in date posts.

    After that I want to show sub-posts (date posts) in the main posts, which means on 100 PKR posts, I want to show all date posts. So I did this;

    <?php $children = get_children( array('post_parent' => get_the_ID()) ); foreach ( $children as $children_id => $child ) { 
    $date = date_create($child->post_title);
    ?>
        <div class="col-md-3 mb-4">
          <a class="d-block" href="<?php the_permalink(); ?>/<?php echo $child->post_title; ?>">
            <i class="fa-regular fa-calendar-days"></i> <?php echo date_format($date,"d / m / Y"); ?><br><?php echo $row->first_prize ?>
          </a>
        </div>
    <?php } ?>

    Now everything is working fine, now I want to show the data of my custom table in this children’s part, which means this children’s part code shows the posts which are under 100 PKR post, it will grab that id from the MySQL table and show it here.

    For Example:

    My SQL

    <?php
    global $wpdb;
    $table = 'wp_prize';
    $prize_bond_id = get_the_ID();
    $query = $wpdb->prepare("SELECT * FROM $table WHERE id=%s;", $prize_bond_id );
    $row = $wpdb->get_row( $query );
    ?>

    Html

      <thead>
        <tr>
          <th>Prize Bond</th>
          <th>Date</th>
          <th>City</th>
          <th>1st Prize</th>
          <th>2nd Prize</th>
          <th>3rd Prize</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td><?php echo $row->prize_bond ?></td>
          <td><?php echo $row->draw_date ?></td>
          <td><span class="city"><?php echo $row->city ?></span></td>
          <td>PKR <?php echo $row->first_prize ?></td>
          <td>PKR <?php echo $row->second_prize ?></td>
          <td>PKR <?php echo $row->third_prize ?></td>
        </tr>
      </tbody>
    </table>

    Also want to show Seprate the by year, means display like this.

    2022 Year
    15-12-2022
    15-09-2022
    15-06-2022
    15-03-2022

    2021 Year
    15-12-2021
    15-09-2021
    15-06-2021
    15-03-2021

    2020 Year
    15-12-2020
    15-09-2020

    I have multiple main posts and date posts

    Main Posts: 100 PKR, 200 PKR, 750 PKR, 1500 PKR, 7500 PKR, 15000, PKR 25000, 25000 PKR Premium, 40000 PKR Premium, 40000 PKR

    And all have so many posts by date and title are with Date (15-12-2022, 15-09-2022, 15-06-2022, 15-03-2022)

    Hope you understand that what i am trying to create

Viewing 2 replies - 16 through 17 (of 17 total)
  • Thread Starter Xaib Aslam

    (@lahorimela)

    Finally i figure it out and its working now. Please ignore my last message which is moderation.

    But my url is like this

    https://mydomain.com/finance/psx/company?company=BILF

    How i can make my url like this

    https://mydomain.com/finance/psx/company/BILF

    I am using the first example which you mentioned @bcworkz

    • This reply was modified 1 year, 8 months ago by Xaib Aslam.
    Thread Starter Xaib Aslam

    (@lahorimela)

    i figured out. thanks for your help @bcworkz

Viewing 2 replies - 16 through 17 (of 17 total)
  • The topic ‘Get Data From Custom Table’ is closed to new replies.