Skip to content

Instantly share code, notes, and snippets.

@magnum
Last active January 27, 2020 17:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magnum/8a0ff34d92ca5b6b94f5a1e57d1dbd5f to your computer and use it in GitHub Desktop.
Save magnum/8a0ff34d92ca5b6b94f5a1e57d1dbd5f to your computer and use it in GitHub Desktop.
wordpress utils
function dbg_print_script($script,$alert=FALSE){
if($alert) echo('<script>alert("'.$script.'");</script>');
echo("<script>$script</script>");
}
function dbg($what){
echo("<pre>".print_r($what, true)."</pre>");
}
function dbg_js($what){
dbg_print_script("console.log(".json_encode($what).");");
}
function get_posts_by_category_name_and_post_type($category_name, $post_type) {
$categories = get_categories_by_category_name($category_name);
$posts_per_category = array();
$posts_list = array();
foreach($categories as $index => $term) {
$query = new WP_Query(array(
'post_type' => $post_type,
'posts_per_page' => -1,
'tax_query' => array(
array(
'taxonomy' => $category_name,
'terms' => $term->term_id,
)
)
));
$posts = $query->posts;
foreach ($posts as $key => $post) {
if(!isset($posts_per_category[$term->term_id])) $posts_per_category[$term->term_id] = array();
$posts_per_category[$term->term_id][] = $post;
$posts_list[] = $post;
}
}
$data = array(
'posts_per_category' => $posts_per_category,
'categories' => $categories,
'posts_list' => $posts_list,
);
dbg($data);
return $data;
}
$config_local = __DIR__."/wp-config.local.php";
if(isset($_GET['test'])) {
print $config_local." exists? ".file_exists($config_local);
exit;
}
if(file_exists($config_local)) {
require($config_local);
return;
}
// other wp-config.local.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment