WordPress.org

Forums

WP-Table Reloaded
[resolved] Custom Export for Table Contents (5 posts)

  1. ragingtalent
    Member
    Posted 2 years ago #

    Hi,

    I'm trying to query two cells of a table for each post I have:

    http://dl.dropbox.com/u/1739837/Screenshots/5a.png

    What is the best way to query these two rows?

    <?php
    /*
    Template Name: Table Export
    */
    ?>
    
    <?php
    global $post;
    $args = array(
    	'numberposts' => 10,
    	'orderby' => 'post_title',
    	'order' => 'DESC',
    	'cat' => 1,
    	'post_status' => 'publish'
    );
    $myposts = get_posts( $args );
    
    foreach( $myposts as $post ) : setup_postdata($post); ?>
    <?php
    $theContent =  get_the_content();
    
    $table_id = false;
    if (preg_match('/\[table\ id=(\d*).*\]/im', $theContent, $r)) {
    	if (isset($r[1])) {
    		$table_id = $r[1];
    	}
    }
    ?>
    
    <div><?php echo $theContent; ?> </div><br /><br />
    <strong>Table Name = <?php  wp_table_reloaded_print_table_info('id=' . $table_id . "&field=name" ); ?></strong><br />
    <strong>Author <?php  wp_table_reloaded_print_table_contents('id=' . $table_id . $row_1 ); ?></strong>
    <strong>Bio <?php  wp_table_reloaded_print_table_contents('id=' . $table_id . $row_2); ?></strong>
    
    <?php endforeach; ?>

    http://wordpress.org/extend/plugins/wp-table-reloaded/

  2. TobiasBg
    Member
    Plugin Author

    Posted 2 years ago #

    Hi,

    the best way for this would be to use the "hide_rows" and "show_rows" parameters. With that, your last two lines would become

    <strong>Author <?php  wp_table_reloaded_print_table('id=' . $table_id . '&hide_rows=all&show_rows=1' ); ?></strong>
    <strong>Bio <?php  wp_table_reloaded_print_table('id=' . $table_id . '&hide_rows=all&show_rows=2' ); ?></strong>

    Technically, this is going to create a HTML table with one row and one column, which is kind of ugly. Therefore, it might be worth to extract the relevant code from http://wordpress.org/support/topic/plugin-wp-table-reloaded-display-content-of-a-cell?replies=18 and to use that to just show the cell contents.

    Now, I have two more things:
    First: If you have just started implementing this with WP-Table Reloaded, I'd actually make a recommendation: Switch to the official and designated successor TablePress now ( http://wordpress.org/extend/plugins/tablepress/ ). This will save you some time when WP-Table Reloaded is being discontinued in favor of TablePress in the near future.
    Secondly: I'm actually not sure that your approach is a good one. From what I can see, you want to use WP-Table Reloaded as a database system, to get data of a clearly defined type (namely information about some person). I can imagine that this would be much better suited for implementation using WordPress Custom Post Types ( http://codex.wordpress.org/Post_Types ), so maybe that's something that you should investigate. With that approach, each person would be a separate post of your new Custom Post Type.

    Regards,
    Tobias

  3. ragingtalent
    Member
    Posted 2 years ago #

    Hey Tobias,

    Thanks for the quick response. So, I tried to use your shortcode example in my code like so:

    Author = <?php do_shortcode('[table_cell c=1 r=1] id='. $table_id .' [/table_cell]') ?>

    What am I doing wrong or is there a better method to use that doesn't use the shortcode?

    Best,

    Jon

  4. ragingtalent
    Member
    Posted 2 years ago #

    Hey Tobias,

    I tried making the updates to your function as well as hard coded a table id and I'm still not getting this.

    http://pastie.org/5531977

    Output:
    http://www.figlancaster.com/table-export

  5. TobiasBg
    Member
    Plugin Author

    Posted 2 years ago #

    Hi,

    on first glance, everything in that pastie looks good.

    Does the [table_cell] Shortcode work in regular post content, i.e. when you insert it into a post or page directly?

    Regards,
    Tobias

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic