fetch data from one databse on the base of two different post_type and make a relation between the,them

Question

Fiest Table

wp_posts

+-----+-------------------+-----------------+----------------------+
| id  | post_title        | post_type       | playlist_example_cat |
+-----+-------------------+-----------------+----------------------+
|  1  | example_channel_1 | chaneel_example |                      |
|  2  | example_channel_2 | channel_example |                      |
|  3  | example_channel_3 | channel_example |                      |
|  4  | example_channel_4 | channel_example |                      |
|  5  | example_channel_5 | channel_example |                      |
|  6  | example_drama_1   | drama_example   | example_channel_1    |
|  7  | example_drama_2   | drama_example   | example_channel_1    |
|  8  | example_drama_3   | drama_example   | example_channel_2    |
|  9  | example_drama_4   | drama_example   | example_channel_3    |
|  10 | example_drama_5   | drama_example   | example_channel_3    |
|  11 | example_drama_6   | drama_example   | example_channel_3    |
|  12 | example_drama_7   | drama_example   | example_channel_5    |
+----+--------------------+-----------------+----------------------+

Second Table

wp_term_taxonomy

+-----------------------+---------+------------------+
| taxonomy              | term_id | term_taxonomy_id |
+-----------------------+---------+------------------+
|  playlist_example_cat | 1       | 1                |
|  playlist_example_cat | 2       | 2                |
|  playlist_example_cat | 3       | 3                |
|  playlist_example_cat | 4       | 4                |
|  playlist_example_cat | 5       | 5                |
+-----------------------+---------+------------------+

What I need
I’m creating a <select><option> dropdown So there are two dropdowns on the page
The first is for Channel and the Second Is for Dramas.
fetching data from the database is easy and I did it From

SELECT * FROM wp_posts WHERE post_type = channel_example

and as same for dramas
Now the problem I’m facing is to make a relation (like Many-to-Many-Relation)
I need a dynamic dropdown So whenever the user select any channel all the dramas of that channel come to the second dropdown menu
So here the Problem
I couldn’t able to fetch playlist_example_cat
don’t know why
Here I show my taxonomy table So you can suggest me a better idea then fetching the playlist_example_cat
Here’s my Php Code

For Channel

<?php
global $wp;
$results = $wpdb-> $results = $wp->get_results("SELECT * FROM wp_posts WHERE post_type = chaneel_example ");
foreach ($results as $key => $program) { 
?>
<div>
<select name="select1" id="select">
    <option value="<?php echo $program->post_title; ?>"> 
      <?php echo $program->post_title; ?>    
    </option>
  </select>
</div>
<?php } ?>

For Drama

<?php
global $wp;
$results = $wpdb-> $results = $wp->get_results("SELECT * FROM wp_posts WHERE post_type = chaneel_example ");
foreach ($results as $key => $program) { 
?>
<div>
<select name="select2" id="select2>
    <option value="<?php echo $program->playlist_example_cat; ?>"> 
      <?php echo $program->post_title; ?>    
    </option>
  </select>
</div>
<?php } ?>

In the console (When I cheak option is something like)

<option value>
example_drama_1
</option>

Can Anybody Is able to solve the Problem

Oh Ya!. I’m using WordPress for this.

Attention : If you need any detail I’ll edit this question Just Comment.

0
MAKSTYLE119 1 month 0 Answers 5 views 0

Leave an answer