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 / 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/
<?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);
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';
@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();
@petrusnog
petrusnog / dropdown-script.js
Created October 14, 2019 14:37
Sistema de dropdowns em jquery
//DROPDOWNS WEART
//Adicione aqui os droptitles
//Dropdowns: Todos os dropdowns
//Close on scroll:Dropdowns que serão fechados mediante scroll
$dropdowns = ["banners", "categories", "painel", "filterby"];
$close_on_scroll = [$dropdowns[2]];
// ============
// SISTEMA DE LIGHTBOX - SamuraiPetrus
// Requer JQuery
//=============
//ABRIR LIGHTBOX
// DESKTOP - height: 515px; width: 815px;
// TABLET - height: 485px; width: 615px;
// MOBILE - height: 315px; width: 305px;
function OpenImageLightBox (content) {
@petrusnog
petrusnog / i9me_functions.php
Last active September 3, 2019 13:52
I9ME FUNCTIONS
<?php
// =========================
// I9ME FUNCTIONS
// =========================
//Console PHP - Desenvolvido por Paulo Arthur e SamuraiPetrus
// (Imprime arrays PHP no Console do Browser)
//=============
// Parâmetros
@petrusnog
petrusnog / functions.php
Last active August 27, 2019 17:13
Modelo Custom Post Type
<?php
public function init() {
$labels_flores = array(
"name" => __( "Flores", "" ),
"singular_name" => __( "Flor", "" ),
"menu_name" => __( "Flores", "" ),
"all_items" => __( "Todas as flores", "" ),
"add_new" => __( "Adicionar nova flor", "" ),
"add_new_item" => __( "Adicionar nova flor", "" ),
// ============
// Excerpt Limiter - Desenvolvido por SamuraiPetrus (https://github.com/SamuraiPetrus)
// (Limitador de string que corta o texto no último espaço em branco)
//=============
// Parâmetros
//=============
//$text -> (str) Texto a ser limitado.
//$chars -> (int) (default: 100) Número de caracteres do texto final.
function excerpt_limiter($str, $chars=100){
@petrusnog
petrusnog / Filtrando posts sem thumbnail
Created May 6, 2019 18:45
WP Query que filtra posts sem thumbnail
$obj = get_queried_object();
$loop = new WP_Query([
'post_type' => "produtos",
'meta_query' => array(
array(
'key' => '_thumbnail_id',
'compare' => 'NOT EXISTS'
)),
'tax_query' => [[
'taxonomy' => 'tipos-produtos',