Skip to content

Instantly share code, notes, and snippets.

View DWboutin's full-sized avatar
🎯
Focusing

Mike Boutin DWboutin

🎯
Focusing
  • Quebec city
View GitHub Profile
@DWboutin
DWboutin / php_curl.php
Last active July 2, 2018 08:14
PHP Curl get content
<?php
$header = array('Accept-Language: en');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
@DWboutin
DWboutin / Merge wp_query
Created February 7, 2014 14:17
Merge 2 WP_Query()
<?php
$query1 = new WP_Query($arg1);
$query2 = new WP_Query($arg2);
$query = new WP_Query();
$query->posts = array_merge( $query1->posts, $query2->posts );
// we also need to set post count correctly so as to enable the looping
@DWboutin
DWboutin / upload-thumnail.php
Last active August 29, 2015 14:00
Wordpress custom upload with thumbnail creation
<?php
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/image.php' );
if(isset($_FILES['photo']['name']) && !empty($_FILES['photo']['name'])){
//Upload la photo dans le dossier
$uploadedfile = $_FILES['photo'];
$movefile = wp_handle_upload($uploadedfile, array('test_form' => false));
@DWboutin
DWboutin / functions.php
Created May 5, 2014 17:50
Wordpress custom the_exerpt length
<?php
function custom_excerpt_length( $length ) {
return 30;
}
add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );
?>
@DWboutin
DWboutin / functions.php
Created May 5, 2014 17:51
Wordpress post view count
<?php
// Compter le nombre de view
// Utiliser wpb_set_post_views($postID) dans toutes les pages à compter les views (single.php)
function wpb_set_post_views($postID) {
$count_key = 'wpb_post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
<?php
function truncate($str, $len){
$strArray = explode(' ', $str);
if(count($strArray) > $len){
$str = array_slice($strArray, 0, $len);
return implode(' ', $str) . '...';
}else{
return $str;
@DWboutin
DWboutin / dir_to_array.php
Created May 6, 2014 13:39
Directory to array
<?php
function dirToArray($dir) {
$result = array();
$cdir = scandir($dir);
foreach ($cdir as $key => $value){
if (!in_array($value,array(".",".."))){
if (is_dir($dir . DIRECTORY_SEPARATOR . $value)){
@DWboutin
DWboutin / functions.php
Created June 16, 2014 12:44
Add Registration field Woocommerce
<?php
//1. Add a new form element...
add_action('register_form','myplugin_register_form');
function myplugin_register_form (){
$first_name = ( isset( $_POST['first_name'] ) ) ? $_POST['first_name']: '';
?>
<p>
<label for="first_name"><?php _e('First Name','mydomain') ?><br />
<input type="text" name="first_name" id="first_name" class="input" value="<?php echo esc_attr(stripslashes($first_name)); ?>" size="25" /></label>
@DWboutin
DWboutin / functions.php
Created June 25, 2014 14:03
Woocommerce get product cat count
<?php
function wp_get_productcat_postcount($id) {
//return $count;
$args = array(
'post_type' => 'product', //post type, I used 'product'
'post_status' => 'publish', // just tried to find all published post
'posts_per_page' => -1, //show all
'tax_query' => array(
@DWboutin
DWboutin / functions.php
Created July 2, 2014 14:26
Custom taxonomy post count
<?php
function catCount($slug){
global $wpdb;
$query = "
SELECT COUNT( DISTINCT cat_posts.ID ) AS post_count
FROM gh_term_taxonomy AS cat_term_taxonomy INNER JOIN gh_terms AS cat_terms ON
cat_term_taxonomy.term_id = cat_terms.term_id
INNER JOIN gh_term_relationships AS cat_term_relationships