Skip to content

Instantly share code, notes, and snippets.

View hslaszlo's full-sized avatar

Laszlo Sebestyen Horvath hslaszlo

View GitHub Profile
/*
* From css-tricks.com
* http://css-tricks.com/snippets/css/media-queries-for-standard-devices/
*/
/* Smartphones (portrait and landscape) ----------- */
@media only screen
and (min-device-width : 320px)
and (max-device-width : 480px) {
/* Styles */
@hslaszlo
hslaszlo / functions.php
Last active January 2, 2016 10:08
Wodpress functions
<?php
// link shortcode
function mainurl_function($atts) {
extract(shortcode_atts(array(
'text' => 'Text',
'url' => 'http://yourdomain.com',
), $atts));
return '<a href="'. $url . '" class="contactlink" >'. $text . '</a>';
}
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
@hslaszlo
hslaszlo / get-category.php
Created April 2, 2015 09:19
Get a category name/slug/id for a post or archive page
<?php
if ( is_single() ) {
$cats = get_the_category();
$cat = $cats[0]; // let's just assume the post has one category
}
else { // category archives
$cat = get_category( get_query_var( 'cat' ) );
}
$cat_id = $cat->cat_ID;
@hslaszlo
hslaszlo / gist:b741049879e075e1e8f9
Created May 14, 2015 14:59
Search by order item SKU or ID in Woocommerce Orders Admin page
//Search by product SKU in Admin Woocommerce Orders
add_filter( 'woocommerce_shop_order_search_fields', function ($search_fields ) {
$posts = get_posts(array('post_type' => 'shop_order'));
foreach ($posts as $post) {
$order_id = $post->ID;
$order = new WC_Order($order_id);
$items = $order->get_items();
foreach($items as $item) {
@hslaszlo
hslaszlo / gist:d0c6357a76d7da56c7cd
Created May 14, 2015 15:02
Display Woocommerce category description
<?php
global $post;
$args = array( 'taxonomy' => 'product_cat',);
$terms = wp_get_post_terms($post->ID,'product_cat', $args);
$count = count($terms);
if ($count > 0) {
foreach ($terms as $term) {
echo '<div style="direction:rtl;">';
@hslaszlo
hslaszlo / gist:afabcbc2a5dd52df8b83
Last active August 29, 2015 14:21
Hierarchical list of taxonomy terms
function return_terms_index() {
$taxonomies = array(
'taxonomy_name',
);
$args = array(
'orderby' => 'name',
'order' => 'ASC',
'hide_empty' => false,
'fields' => 'all',
@hslaszlo
hslaszlo / get-attachment-id.php
Last active August 29, 2015 14:21
Get an attachment ID by URL in WordPress
<?php
// source: http://frankiejarrett.com/get-an-attachment-id-by-url-in-wordpress/
$url = 'http://frankiejarrett.com/wp-content/uploads/2013/05/test-image.jpg';
$attachment_id = fjarrett_get_attachment_id_by_url( $url );
$path = ( $attachment_id ) ? get_attached_file( $attachment_id ) : null;
echo $path;
?>
@hslaszlo
hslaszlo / get-first-category.php
Last active August 29, 2023 10:18
Get first category name or id from wordpress post
<?php
// in the loop
$category = get_the_category();
$currentcat = $category[0]->cat_ID;
$currentcatname = $category[0]->cat_name;
$currentcatslug = $category[0]->slug;
// outside the loop
global $post;
$categories = get_the_category($post->ID);
@hslaszlo
hslaszlo / gist:86640510c79cb45f8696
Created July 5, 2015 07:40
Flexible horizontal widgets
<?php
/**
* Count number of widgets in a sidebar
* Used to add classes to widget areas so widgets can be displayed one, two, three or four per row
* source: http://slobodanmanic.com/444/flexible-horizontal-sidebars-wordpress-twenty-thirteen-child-theme/
*/
function slbd_count_widgets( $sidebar_id ) {
// If loading from front page, consult $_wp_sidebars_widgets rather than options
// to see if wp_convert_widget_settings() has made manipulations in memory.