Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to insert data in table and fetch in wordpress

if (isset($_REQUEST['unfollow'])) {
    global $wpdb;
    $table_name = $wpdb->base_prefix . 'bp_follow';
    $current_user = $_REQUEST['current_user'];
    $author_user = $_REQUEST['author_user'];
    //$wpdb->query($wpdb->prepare("DELETE * FROM ".$table_name." where leader_id=".$author_user." and follower_id=".$current_user));
    $wpdb->delete($table_name, array('leader_id' => $author_user, 'follower_id' => $current_user,));
    echo "<script type='text/javascript'>
        window.location=document.location.href;
        </script>";
}

if (isset($_REQUEST['follow'])) {
    $current_user = $_REQUEST['current_user'];
    $author_user = $_REQUEST['author_user'];
    $table_name = $wpdb->base_prefix . 'bp_follow';
    global $wpdb;
    $wpdb->insert($table_name, array(
        "follower_id" => $current_user,
        "leader_id" => $author_user,
    ));
   echo "<script type='text/javascript'>
        window.location=document.location.href;
        </script>";
}

function follow_btn($current_user, $author_id)
{

    global $wpdb;
    $table_name = $wpdb->base_prefix . 'bp_follow';
    $results = $wpdb->get_results("SELECT follower_id FROM " . $table_name . " where leader_id=" . $author_id . " and follower_id=" . $current_user);
    //var_dump($results);
    if ($results) {
        return "<div class='follow_div'>
						<form method='post' action=''>
			      <button type='submit' name='unfollow'>Unfollow me</button>
				  <input type='hidden' name='current_user' value='" . $current_user . "' />
				  <input type='hidden' name='author_user' value='" . $author_id . "' />
				  </form>
			     </div>";
    } else {
        return "<div class='follow_div'>
						<form method='post' action=''>
						 <input type='hidden' name='current_user' value='" . $current_user . "'  />
				  <input type='hidden' name='author_user'   value='" . $author_id . "' />
			<button type='submit' name='follow'>Follow me</button>
			</form>
			</div>";
    }
}

front page
  $t_id = get_queried_object_id();;
  $author_meta = get_option("taxonomy_term_$t_id");
  $current_user = get_current_user_id();
  echo follow_btn($current_user, $author_meta['presenter_id']);
Comment

PREVIOUS NEXT
Code Example
Php :: php static variable 
Php :: php unit 
Php :: IlluminateContractsAuthAuthenticatable, AppModelsUser given, called in 
Php :: job with queue name 
Php :: how to redirect to another page in php after submit 
Php :: get current locale laravel 
Php :: Undefined constant "STDOUT" in php 
Php :: laravel create on model 
Php :: php print object 
Php :: get pages with template wp php 
Php :: switch php version ubuntu 20.04 
Php :: nginx codeigniter remove index.php 
Php :: array value search in php 
Php :: PHP str_repeat — Repeat a string 
Php :: Laravel jwt check token sent by request is valid 
Php :: php file upload ajax 
Php :: filter wordpress 
Php :: session forget laravel 
Php :: vs code php tag shortcut 
Php :: session start php 
Php :: laravel invoice toturial 
Php :: How to Customize WooCommerce Breadcrumb 
Php :: laravel get all request parameters 
Php :: laravel sharing image 
Php :: how to pass data to controller in laravel 
Php :: resource route laravel 8 
Php :: display all files in a directory php 
Php :: php localhost:8000 
Php :: Corsair K70 RGB MK.2 
Php :: symfony form submit on refresh 
ADD CONTENT
Topic
Content
Source link
Name
9+7 =