Skip to content

Instantly share code, notes, and snippets.

View petrusnog's full-sized avatar
🏠
Coding from home

Petrus Nogueira petrusnog

🏠
Coding from home
  • Fortaleza - CE
View GitHub Profile
@petrusnog
petrusnog / main.js
Last active September 11, 2020 13:56
My first experience using Ajax with pure JavaScript.
var httpRequest;
if (window.XMLHttpRequest){
httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) {
httpRequest = new ActiveXObject();
DELETE relations.*, taxes.*, terms.*
FROM wp_term_relationships AS relations
INNER JOIN wp_term_taxonomy AS taxes
ON relations.term_taxonomy_id=taxes.term_taxonomy_id
INNER JOIN wp_terms AS terms
ON taxes.term_id=terms.term_id
WHERE object_id IN (SELECT ID FROM wp_posts WHERE post_type='product');
DELETE FROM wp_postmeta WHERE post_id IN (SELECT ID FROM wp_posts WHERE post_type = 'product');
DELETE FROM wp_posts WHERE post_type = 'product';
<?php
function curl_request ($url, $method="GET", $return_transfer=true, $timeout=50) {
$ch = curl_init($url);
$info = curl_getinfo($ch);
//OPTIONS
curl_setopt($ch, CURLOPT_RETURNTRANSFER, $return_transfer);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
@petrusnog
petrusnog / get_taxonomies_tree.php
Last active March 6, 2020 18:43
PHP function that retrieves an array with all the taxonomies of certain WordPress Post Type.
<?php
//===============================================
// PHP function that retrieves an array with all
// the taxonomies of certain WordPress Post Type.
// By: SamuraiPetrus
//===============================================
// $taxonomies = get_object_taxonomies('your-post-type');
// Codex get_object_taxonomies : https://developer.wordpress.org/reference/functions/get_object_taxonomies/
@petrusnog
petrusnog / brazilian_real_notation.php
Created May 14, 2020 19:34
Brazilian Real Notation - A simple PHP snipppet to convert numbers to brazilian real currency.
function brazilian_real_notation ( $price = 0 ) {
return "R$" . number_format($price, 2, ',', '.');
}
//SISTEMA DE DROPDOWNS
//Configurações dos dropdowns
//Argumentos
// [0] => (String) (Obrigatório) Título,
// [1] => (Boolean) (Default: false) Apenas Mobile,
// Para manter os valores padrões, adicione apenas o título no array $dropdowns
// Para modificar os valores padrões, adicione um array no array $dropdowns com as modificações
@petrusnog
petrusnog / lightbox-template.php
Last active June 2, 2020 00:09
Sistema de Lightbox para vídeos
<?php
//wp_is_ipad vai em functions.php
function wp_is_ipad ( ) {
if( strpos($_SERVER['HTTP_USER_AGENT'], 'iPad') ) {
return true;
} else{
return false;
}
}
@petrusnog
petrusnog / get_filtered_terms.php
Last active July 17, 2020 14:27
Filtrar termos de produtos filtrados por tax e meta query. (Ex: Exibir as categorias de todos os produtos fora de estoque)
<?php
function get_filtered_terms ( $post_type, $taxonomy, $tax_query = 0, $meta_query = 0 ) {
//Filtra os posts de acordo com a filtragem passada
$args = [
"post_type" => $post_type,
"posts_per_page" => -1,
];
if ( $tax_query ) {
@petrusnog
petrusnog / product_visibility_hidden.php
Created July 20, 2020 22:36
Script that set all Woocommerce's "Product Visibility" to "Hidden"
<?php
$args = array(
"post_type" => "product",
"posts_per_page" => -1,
);
$post_query = new WP_Query($args);
if ( $post_query->have_posts() ) {
@petrusnog
petrusnog / listas.html
Created September 29, 2020 03:49
Lista de contatos - My First Vue.js Application!
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="utf-8">
<title>Lista de contatos</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css">
<style media="screen">
#vueroot{