Notice: These forums are now retired and closed. For active support, please Submit a Ticket or visit our official WordPress.org community pages.
Kadence Theme | Kadence Blocks | Starter Templates | WooCommerce Email Designer | Ascend | Virtue | Pinnacle

Search Results for 'post'

Home / Forums / Search / Search Results for 'post'

Viewing 2 results - 29,721 through 29,722 (of 29,722 total)
  • Author
    Search Results
  • #352

    Hi I like the search form that is at the top f the page but the results it returns I don’t like. For the purposes of woocommerce, is it possible to set such that it will only return results from the products published to the site just like the plugin “search-by-sku-for-woocommerce”? Here is this plugins code:

    <?php

    /*
    Plugin Name: Search By SKU – for Woocommerce
    Plugin URI:
    Description: The search functionality in woocommerce doesn’t search by sku by default. This simple plugin adds this functionality to both the admin site and regular search
    Author: Matthew Lawson
    Version: 0.4
    Author URI:
    */

    add_filter(‘the_posts’, ‘variation_query’);

    function variation_query($posts, $query = false) {
    //var_dump($posts);die();
    if (is_search())
    {
    $ignoreIds = array(0);
    foreach($posts as $post)
    {
    $ignoreIds[] = $post->ID;
    }

    //get_search_query does sanitization
    $matchedSku = get_parent_post_by_sku(get_search_query(), $ignoreIds);

    if ($matchedSku)
    {
    foreach($matchedSku as $product_id)
    {
    $posts[] = get_post($product_id->post_id);

    }

    }
    return $posts;
    }

    return $posts;
    }

    function get_parent_post_by_sku($sku, $ignoreIds) {
    //Check for
    global $wpdb, $wp_query;

    $results = array();
    //Search for the sku of a variation and return the parent.
    $ignoreIdsForMySql = implode(“,”, $ignoreIds);
    $variations = $wpdb->get_results(

    SELECT p.post_parent as post_id FROM $wpdb->posts as p
    join $wpdb->postmeta pm
    on p.ID = pm.post_id
    and pm.meta_key=’_sku’
    and pm.meta_value LIKE ‘%$sku%’
    join $wpdb->postmeta visibility
    on p.post_parent = visibility.post_id
    and visibility.meta_key = ‘_visibility’
    and visibility.meta_value <> ‘hidden’
    where 1
    AND p.post_parent <> 0
    and p.ID not in ($ignoreIdsForMySql)
    and p.post_status = ‘publish’
    group by p.post_parent

    );

    //var_dump($variations);die();
    foreach($variations as $post)
    {
    //var_dump($var);
    $ignoreIds[] = $post->post_id;
    }
    //If not variation try a regular product sku
    //Add the ids we just found to the ignore list…
    $ignoreIdsForMySql = implode(“,”, $ignoreIds);
    //var_dump($ignoreIds,$ignoreIdsForMySql);die();
    $regular_products = $wpdb->get_results(
    “SELECT p.ID as post_id FROM $wpdb->posts as p
    join $wpdb->postmeta pm
    on p.ID = pm.post_id
    and pm.meta_key=’_sku’
    AND pm.meta_value LIKE ‘%$sku%’
    join $wpdb->postmeta visibility
    on p.ID = visibility.post_id
    and visibility.meta_key = ‘_visibility’
    and visibility.meta_value <> ‘hidden’
    where 1
    and (p.post_parent = 0 or p.post_parent is null)
    and p.ID not in ($ignoreIdsForMySql)
    and p.post_status = ‘publish’
    group by p.ID

    “);

    $results = array_merge($variations, $regular_products);
    #var_dump($variations,$regular_products);
    //var_dump($results);
    $wp_query->found_posts += sizeof($results);

    return $results;
    }

    ?>

    In forum: Virtue Theme
    #156

    The Kadence team’s top priority is your success with our products. To that end, we do not provide general WordPress support here, or support for third-party plugins or code. You’ll need to ask for help with general WordPress questions here:

    We are all tinkerers and geeks to our core, and love to see folks modify and tinker with Kadence products to fit their needs. Given unlimited time, we’d be jumping in and helping at every turn. The community forum here is full of folks that can help, but if it’s more than a few lines of code or a simple fix, our team is going to consistently refer you to third-party developers to get things done.

    Finally, never post your site’s credentials or give credentials to other users here on the forums. Team members will not ask for those credentials here, and team members are clearly noted as “Support Team Members.”

Viewing 2 results - 29,721 through 29,722 (of 29,722 total)