Print serialized data from phpmyadmin saved using cf7db - wordpress

I want to build a custom php page that shown registered user from wp,the data saved from wp is a serialized data and i got problem to display. btw i am using contact form 7 database plugin.
i keep getting explode() expect parameter to be string and getting error on line 10.
<?php
//connect database
$conn=new mysqli("localhost","root","","testsaja2");
//call a field from table
$sql= "select form_value from wp_db7_forms";
$result=mysqli_query($conn,$sql);
while($string=mysqli_fetch_array($result));
$explode = explode(PHP_EOL, $string);
foreach ($explode as $line) {
?>
<?php
foreach (unserialize($line) as $item => $value){
?>
<tr>
<td><b><?php echo $item . ": ";?></b></td>
<td><?php if ($value == 'email'){
foreach ($value as $data) {
echo $data ;
}
}
else {
echo $value;
}
?> </td>
</tr>
<br>
<?php } ?>
</table>
<?php } ?>

Modify your code to this.
<?php
//connect database
$conn=new mysqli("localhost","root","","testsaja2");
//call a field from table
$sql= "select form_value from wp_db7_forms";
$result=mysqli_query($conn,$sql);
while($string=mysqli_fetch_array($result)){
$unserialize = unserialize($string['form_value']);
foreach ($unserialize as $item => $value){
?>
<tr>
<td><b><?php echo $item . ": ";?></b></td>
<td><?php echo $value; ?> </td>
</tr>
<?php
} }?>
</table>

Related

wp post metadata showing in backend but not frontend / same code

Situation:
using a php file (table_template.php) with include_once to show meta data. Using this template in the backend (inside a metabox) shows everything as it should - using the same template on the frontend (inside a post) the table metadata do not show (but other meta data from custom fields do).
var dump in the backend:
string(65) "[["test value 1","test value 2","test value 3"],["test value a","test value b","test value c"]]"
var dump on the frontend:
string(6) "[[""]]"
code from table_template.php:
<?php
/* TEMPLATE TO RENDER THE TABLE (AS PREVIEW) IN THE BACKEND AND FRONTEND */
global $post;
$table_meta = get_post_meta( $post->ID, 'psg_table_meta', true ) ?
get_post_meta( $post->ID, 'psg_table_meta', true ) : '[[""]]';
$t = json_decode( $table_meta );
$c_id = get_post_meta( $post->ID );
$c = get_post( $c_id );
?>
<div class="psg_box_table">
<table class="psg_table ">
<thead>
<tr>
<?php foreach ( $t[ 0 ] as $col ): ?>
<th>
<?php echo $col; ?>
</th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ( $t as $idx => $row ): ?>
<?php if ( $idx == 0 )
continue; ?>
<tr>
<?php foreach ( $row as $col ): ?>
<td>
<div class="psg_table_content">
<?php echo str_replace( '"', '"', $col ) ?>
</div>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<!--END SIZING CHART TABLE -->
How i load the Template:
include_once( "table_template.php" );
If you are using the template inside loop of WP_Query, then replace
$post->ID
with
get_the_ID();
Also check the psg_table_meta key is correct one.
The issue was, that i should not check for the postID (the table meta data is not directly in the post, but in a selected/linked post within it. So i had to replace
$table_meta = get_post_meta( $post->ID, 'psg_table_meta', true ) ?
with
$table_meta = get_post_meta( $psg_selected, 'psg_table_meta', true ) ?

WP event manager widget only show if there is some events

i want to show event title if there is some events, if no event is there i dont want to show event title. how can i solve this problem, please help me. iam using Event Manager plugin.sorry for my bad english
Step 1 : Inside your WP site there is the following path: \site.com\wp-content\themes\theme_name\functions.php
*In case of not having this file you created.
Step 2 : Please insert into file functions.php the following code:
<?php
function em_mod_custom_events_list(){
$events = EM_Events::get(array('scope'=>'future','limit'=>10));
?>
<table>
<tbody>
<?php
$start = false;
$limit = 3;
$count = 1;
foreach( $events as $EM_Event ){
if ( !empty($EM_Event->event_name) ){
?>
<?php if ( !$start ) { ?>
<tr>
<?php $start = true; ?>
<?php } ?>
<td><?php echo $EM_Event->output("#_EVENTLINK"); ?></td>
<?php
if ( $count == $limit ){
?>
</tr>
<?php
$start = false;
$count = 1;
}else{
$count++;
}
?>
<?php
}
}
?>
</tbody>
</table>
<?php
}
Step 3 : Save file and Test
1) Using templates --> http://wp-events-plugin.com/documentation/using-template-files
2) Create your own page event --> http://wp-events-plugin.com/tutorials/create-custom-event-information-pages/
The documentation is quite clear and you can help.

I am trying to sort this table by user_meta org and right now it sorts by username.

I am trying to sort this table by user_meta 'org' and right now it sorts by username. Please help. Thanks!
<table width="100%" border="0" cellpadding="0">
<tbody>
<?php
// Get all users order by amount of posts
$allUsers = get_users('order=ASC');
$users = array();
// Remove subscribers from the list as they won't write any articles
foreach($allUsers as $currentUser)
{
if(!in_array( 'administrator', $currentUser->roles ))
{
$users[] = $currentUser;
}
}
?>
<?php get_header(); ?>
<?php
foreach($users as $user)
{
?>
<tr>
<th><?php echo get_user_meta($user->ID, 'org', true); ?></th>
<td scope="row"><?php echo $user->first_name . " " . $user->last_name; ?></td>
<td><?php echo get_user_meta($user->ID, 'pnumber', true); ?></td>
<td><?php echo $user->user_url; ?></td>
</tr>
<tr>
<?php
}
?>
</tbody>
I am trying to loop through account names and meta info and put them in the order_by user_meta org. Please help. Thanks in advance!
Well, a start could be to use the orderby parameter of the query in get_users. But it only works for the following fields: 'ID', 'login', 'nicename', 'email', 'url', 'registered', 'display_name', or 'post_count' for example:
$allUsers = get_users('order=ASC&orderby=ID'); // the default orderby is login
(see http://codex.wordpress.org/Function_Reference/get_users)
But if I understood correctly, seems like what you actually need to do is something like
$users[] = $currentUser;
$user_org = get_user_meta($currentUser->ID, 'org'); // read user_meta org
$user[count($user-1)]->org = $user_org;
(see http://codex.wordpress.org/Function_Reference/get_user_meta)
in your control structure and then re sort the array according to the 'org' value. How? http://www.php.net/manual/en/array.sorting.php

Meta Box Not Showing up in The Admin Page

Using WordPress 3.7.1 and PHP 5.4.12 I am trying to add a Meta box - text field to my Custom Post Type. My custom Post Type name is "news" and this is my code:
<?php
/* Custom Meta Boxex */
add_action('add_meta_boxes', 'my_cmbox_add');
add_action('save_post', 'save_options');
function my_cmbox_add()
{
add_meta_box(
"prodInfo-meta",
"News Source ",
"news_source",
"news",
"normal",
"low"
);
}
function news_source()
{
global $post;
$custom = get_post_custom($post->ID);
$source = $custom['source'][0];
?>
<table>
<tr>
<td><?php echo '<label>News Source :</label>'; ?></td>
<td><?php echo '<input name="source" value="'. $source . '" style="width:250px;" />'; ?></td>
</tr>
</table>
<?php
}
function save_options()
{
global $post;
if (!isset($_POST['source']) || $post->post_type != 'news')
{
return $post;
}
update_post_meta($post->ID, "source", $_POST['source']);
}
I am not getting any error but as I said nothing show up in the page. Can you please let me know what I am doing wrong here?
Try to pass parameters .
function my_cmbox_add()( $post_type, $post );
You can also try and use add_meta_boxes_{post_type} for best practice.

How to display the_meta() of a Wordpress custom page in a table

I have some meta values on my wordpress custom page that I need to be displayed in a table. Is there any way I can do that.
Here's the code I'm using now: <?php the_meta(); ?>
And this is what it shows:
I want to do something like:
I found out that:
the_meta() is located in wp-includes/post-template.php
This makes the output:
<ul class='post-meta'>
<li><span class='post-meta-key'>your_key:</span> your_value</li>
</ul>
So it's not recommended to edit files in that folder because of the wordpress update.
<table>
<tr><td colspan="2">Game Summary</td></tr>
<?php
$meta = get_post_meta( get_the_ID() );
$exclude = array('_edit_last', '_wp_page_template', '_edit_lock');
foreach( $meta as $key => $value ) {
if( in_array( $key, $exclude) )
continue;
?>
<tr>
<td><?php echo $key; ?></td>
<td><?php echo $value[0]; ?></td>
</tr>
<?php
}
?>
</table>

Resources