wordpress custom code


<p><?php query_posts(‘page_id=161’);
if(have_posts()) : the_post(); ?></p>

<h2><a href=”<?php the_permalink() ?>” rel=”bookmark”><?php the_title(); ?></a></h2>
<?php    the_content();
endif;
?>

—————–login condition————
<?php
if ( is_user_logged_in() ) {
?>

html text

<?php
} else {
?>

html text

<?php } ?>

——————–desplay user name ———————-

<?php global $current_user;
get_currentuserinfo();
echo $current_user->display_name;
?>

—-send mail click on url in wordpress————————————-
if($_GET[‘conf’])
{
$to = $_GET[‘conf’];
//echo ($_GET[‘conf’]) ;
$email_from =”jossreal@hotmail.com”;

$subject = “Test”;
$message=”hello”;
$headers = “From: $email_from \r\n”;

if(wp_mail( $to, $subject, $message, $headers ))
{
echo”done”;
}

}?>

————–show —confirm pop ——————-
function myFunction()
{
var x;
var r=confirm(“Press a button!”);
if (r==true)
{
x=”You pressed OK!”;
}
else
{
x=”You pressed Cancel!”;
}
document.getElementById(“demo”).innerHTML=x;
}

==================insert data in wordpress database ===========================

<?php
if(!empty($_POST)) {
global $wpdb;
$table = ‘wp_unlocking_data’;
$data = array(
‘brand’ => $_POST[‘brand’],
‘model’    => $_POST[‘model’],
‘carrier’    => $_POST[‘carrier’],
‘imei_number’    => $_POST[‘imei’],
‘message’    => $_POST[‘message’],
‘status’ => ‘Pending’,
‘date’ => date(“Y-m-d”),
‘user_id’=> $current_user->user_login
);
$format = array(
‘%s’,
‘%s’,
‘%s’,
‘%s’,
‘%s’,
‘%s’,
‘%s’,
‘%s’
);
$success=$wpdb->insert( $table, $data, $format );
if($success){
?>
<script>
alert(“Data Saved Successfully”);
</script>
<?php

}
}
?>

===================================select data from wordpress database============================
<?php
global $wpdb;

$querystr = ”
SELECT * FROM $wpdb->users where freelancer_Id =’1′
“;

$pageposts = $wpdb->get_results($querystr, OBJECT);
echo(“<pre>”);
print_r($pageposts);
echo(“</pre>”);
?>

=================================================================
<?php

$result = $wpdb->get_results ( “SELECT * FROM wp_users where freelancer_Id =’1′ ” );
foreach ( $result as $print )   {
?>

<?php echo get_avatar( $id_or_email, $size, $default, $alt ); ?>
<?php echo $print->first_name;?>
<?php } ?>

=====================condition-==for last insert id =======
<?php
global $wpdb;
if( $wpdb->insert_id ){
$result = $wpdb->get_results ( “SELECT * FROM Applications application_id='”.$wpdb->insert_id.”‘” ” );
foreach ( $result as $print )

{

}

echo “values”
?>

 

how to use update query in wordpress database

<?php
if(!empty($_POST)){
global $wpdb;
$wpdb->show_errors();
$table = ‘Applications’;
$data = array(
‘offer_of_client_bid_amount’ =>$_POST[‘offer_of_client_bid_amount’],
‘offer_of_client_total_charged_to_client’ => $_POST[‘offer_of_client_total_charged_to_client’],
‘offer_of_client_upfront_payment’=> $_POST[‘offer_of_client_upfront_payment’],
‘offer_message_to_freelancer’ => $_POST[‘offer_message_to_freelancer’],
‘accept_message_to_client’=>$POST[‘accept_message_to_client’]
);
$format = array(
‘%s’,
‘%s’,
‘%s’,
‘%s’,
‘%s’
);
$where= array (‘job_Id’=>12);
$whereformat= array (‘%d’);
$success=$wpdb->update( $table, $data,$where ,$format, $whereformat );
if($success){
?>
<?php
echo “Thank you for send offer  “;
}
else
{
echo “not submitted data”;
}
?>
<?php    } ?>

 

 

/****************display car model and  category and  custom  category ******************/

 

<?php

$terms = get_terms(“vehicle_model”,’parent=0′);
$count = count($terms);

if ( $count > 0 ){

foreach ( $terms as $term ) {

?>
<div style=”padding-bottom:5px;padding-top:5px;width:25%;height:auto;float:left;text-align:center”>
<a style=” color: black !important; font-size: 14px;  ” href=”<?php echo get_term_link( $term );?>”>
<?php echo($term->name); ?>
</a>
</div>

<?php

}

}

?>

 

 

 

how to display post meta without post id in wordpress

 

global $wpdb;

$metas = $wpdb->get_results(
$wpdb->prepare(“SELECT meta_value FROM $wpdb->postmeta where meta_key = %s”, ‘add_your_key_here’)
);

echo ‘<pre>’;
print_r( $metas );
echo ‘</pre>’;

 

Leave a comment