0
votes

Our Wordpress site are infected and we are deleted all files. we have now only database and want to extract all information from db and afther this copy on other site.

so I am using this php class to connect db and call some information. I am calling now posts with data, but need categories also.

For example:

Post Title, Post Content, Post Category

here is my working code without category names

$posts = $db->get('c3624322676f_wp_posts'); 

but I have no idea how to call categories names here.

This is my html + foreach

<table class="table table-hover">
  <thead class="thead-inverse">
    <tr>
      <th>#</th>
      <th>Title</th>
      <th>Type</th>
      <th>Content</th>
      <th>Action</th>
    </tr>
  </thead>
  <tbody>
  <?php foreach ($posts as $post) : ?>
    <tr>
      <th scope="row"><?php echo $count++; ?><a href=""></th>
      <td><?php echo $post['post_title']; ?></td>
      <td><?php echo $post['post_type']; ?></td>
      <td><?php echo strip_tags ($post['post_content']); ?></td> 
      <td>
      <form action="" method="post">
        <input type="hidden" name="id" value="<?php echo $post['ID']; ?>" />
        <input style="cursor:pointer;" type="submit" class="btn btn-primary" value="Delete" />
      </form>     
      </td> 
    </tr>
  <?php endforeach; ?>
  </tbody>
</table> 
1

1 Answers

0
votes

This should work

    <table class="table table-hover">
  <thead class="thead-inverse">
    <tr>
      <th>#</th>
      <th>Title</th>
      <th>Type</th>
      <th>Content</th>
      <th>Action</th>
    </tr>
  </thead>
  <tbody>
  <?php foreach ($posts as $post) : ?>
    <tr>
      <th scope="row"><?php echo $count++; ?><a href=""></th>
      <td><?php echo $post['post_title']; ?></td>
      <td><?php echo $post['post_type']; ?></td>
      <td><?php echo strip_tags ($post['post_content']); ?></td>

      <?php 
            $separator = ',';
            $output = '';
            $categories = get_the_category($post['post_title']);
            if ($categories){

                foreach($categories as $category) {
                    $output .= '<a href="'.get_category_link( $category->term_id ).'" title="' . esc_attr( sprintf( __( "View all posts in %s" ), $category->name ) ) . '">'.$category->cat_name.'</a>'.$separator;
                }

            echo trim($output, $separator);
            }
       ?>      
      <td>
      <form action="" method="post">
        <input type="hidden" name="id" value="<?php echo $post['ID']; ?>" />
        <input style="cursor:pointer;" type="submit" class="btn btn-primary" value="Delete" />
      </form>     
      </td> 
    </tr>
  <?php endforeach; ?>
  </tbody>
</table>