Sorry, you are not allowed to access this page after wp-admin login

If you see the following text, Sorry, you are not allowed to access this page. after logging into WP admin.
Screen Shot 2017-08-27 at 17.30.52

Then you might have change the database prefix. Usermeta table contains

Where the prefix bz_ is the database prefix specified in wp-config.php

Proof from the source code at

WooCommerce check if product in cart is in stock

Check if product in cart is in stock:

foreach (WC()->cart->cart_contents as $item) {
    $product_id = isset($item['variation_id']) ? $item['variation_id'] : $item['product_id'];
    $product = new \WC_Product_Factory();
    $product = $product->get_product($product_id);
    if ($item['quantity'] > $product->get_stock_quantity()) {
        $inStock = false;

WordPress custom search for custom post type

After creating a custom post type for an Inventory plugin the client needed also customized search for the columns.

Custom search for custom post type

First the pre_get_posts looked as a good candidate for hooking, but ended up with filtering via posts_clauses_request

add_filter('posts_clauses_request', 'customSearchClause');
function customSearchClause($query)
    global $wp_query;

    if (!is_search()) {
        return $query;

    $term = $wp_query->query['s'];
    $query['join'] = 'INNER JOIN wp_postmeta ON (wp_posts.ID = wp_postmeta.post_id)';
    $query['where'] = "AND wp_posts.post_type = '$this->post_type'
    AND (
        (wp_posts.post_title LIKE '%{$term}%')
        OR (wp_postmeta.meta_key = 'product' AND wp_postmeta.meta_value LIKE '%{$term}%')
        OR (wp_postmeta.meta_key = 'product_code' AND wp_postmeta.meta_value LIKE '%{$term}%')

    return $query;

Use WordPress core as PHP framework

For a task I required using headless WordPress, just the core without a template. Using as a PHP framework. More info about integration is available at

Power tip:
To avoid plugins redirecting after requiring wp-blog-header.php define DOING_CRON const or might be DOING_AJAX or WP_ADMIN. Gist snippet. You could also check defined constants. To avoid redirect you also might redefine wp_redirect() function.



define('DOING_CRON', true);
require dirname(__FILE__).'/wp-blog-header.php';

// Your code goes here...

My first WordPress plugin

Finally finished my first WordPress plugin. With the help of  Woocommerce CSV importer I successfully imported 4175 products into WooCommerce and needed to import attributes. WP All Import is a very good paid alternative (tried there awesome demo), but as a newcomer coder I wanted to learn WP so wrote the plugin that imports those attributes.

The plugin to import
Set product attributes
All attributes
DB stats for 4175 products with their attributes