Searching Posts Programmatically in a WordPress Plugin

If I navigate to Posts -> All Posts in a WordPress install, there’s a Search Box in the upper right hand corner. Entering terms in this box and clicking the Search Posts button will perform a search.

Does WordPress provide a hook, function, or other API that would allow me to programmatically perform the same (or a similar) search? i.e. I pass in a string as terms and get back a PHP array of results without needing to write any SQL myself.

If not, does anyone here know where in the WordPress core code the above search happens? (so I cam mimic the behavior as best as possible)

Count search results

On my wordpress search page I would like to show a ‘total found results’. This needs to be shown at the top of the page in a heading.

I’ve tried this code but I gives me only the results of the specific page. What I want is all the results, not just the page.

 

WordPress how to find where a shortcode comes from

Just use the Windows search bar in wp-content directory and search for companyName_apply_form. You should find the file where the shortcode is created.

To add a shortcode in WordPress you normally use this syntax:

So with basic linux skills, you can find the function_name + file that define the shortcode_name

… and the results

 

WordPress how to get current url woocommerce product

I am trying to get Woocommerce product permalink by given product name. I know I can get permalink by given product ID like this:

But I can not find any code to get it by product name. I tried this:

Or in the woocommerce template, you can follow the following snippets

WordPress Get ID of Current Category

Getting the ID of the current category in WordPress is actually quite simple.

How can I retrieve slug of current taxonomy being viewed in taxonomy template?

To further explain, lets say I am viewing category flowers so how can I retrieve slug of category flowers?

We are going to use get_queried_object() to accomplish this task. The following script will get all the information about our queried object and put it in an array, $category. Then we are simply getting the term_id from that array and echoing it.

You can get the term object of the category you’re viewing with get_queried_object(). That will contain the slug.

Just place that code in any template file where a category has been queried, such as category archive pages, and you will be able to get the category id no problem.

WordPress how to find the source of a shortcode

I am working with wordpress and want to change the output of a shortcode that I wrote myself earlier. Because I forgot where I put it (bad organizing when I started with wp) I wondered whether there is a list of all shortcodes with their source files in the wp database somewhere?

You can use the following code to get a list of all registered shortcodes.

This will unfortunately not give you the source files of these shortcodes but a simple search through your plugins and themes should reveal the location of the shortcode.

How to send requests through a Proxy in Python 3 using Requests

In this blog post we will show you how to send your requests to a website using a proxy, and then we’ll show you how to send these requests through multiple IP addresses or proxies.

How to send requests through a Proxy in Python 3 using Requests

If you are using Python-Requests, you can send requests through a proxy by configuring the proxies argument. For example

We’ll show how to send a real request through a free proxy.

How to check version of python modules

I suggest using pip in place of easy_install. With pip, you can list all installed packages and their versions with

In most linux systems, you can pipe this to grep to find the row for the particular package you’re interested in:

For an individual module, you can try the __version__ attribute, however there are modules without it:

Lastly, as the commands in your question are prefixed with sudo, it appears you’re installing to the global python environment. Strongly advise to take look into python virtual environment managers, for example virtualenvwrapper

WordPress backup database with wp command

 

WordPress create term programmatically with wp_insert_term

A non-existent term is inserted in the following sequence: 1. The term is added to the term table, then related to the taxonomy. 2. If everything is correct, several actions are fired. 3. The term_id_filter is evaluated. 4. The term cache is cleaned. 5. Several more actions are fired. 6. An array is returned containing the term_id and term_taxonomy_id.

If the slug argument is not empty, then it is checked to see if the term is invalid. If it is not a valid, existing term, it is added and the term_id is given.

If the taxonomy is hierarchical, and the parent argument is not empty, the term is inserted and the term_id will be given.

Error handling: If $taxonomy does not exist or $term is empty, a WP_Error object will be returned.

If the term already exists on the same hierarchical level, or the term slug and name are not unique, a WP_Error object will be returned.

Examples code

 

Parse JSON – Convert from JSON to Python

If you have a JSON string, you can parse it by using the json.loads() method.

The result will be a Python dictionary.

Example

Convert from JSON to Python: