You need the wordpress category ID for a given category name (e.g.
My category), e.g. for a shortcode filter.
You can use a SQL statement to find the correct category for your term (i.e. the category name,
My category). Run this statement in your database administration interface, e.g. phpmyadmin.
SELECT termtax.term_taxonomy_id FROM wp_terms AS terms JOIN wp_term_taxonomy AS termtax ON terms.term_id = termtax.term_id WHERE terms.name = "My category"
My category at the end by the category name you’re looking for.
You have a post that has been translated into multiple languages using WPML.
You want to find out the ID of the original post, i.e. the equivalent post in the source langugae.
As far as I know, there is no WPML API for this. You can, however, use
$wpdb in order to query the database directly.
Here’s the SQL statement:
FROM wp_icl_translations AS trans1
INNER JOIN wp_icl_translations AS trans2
ON trans2.trid = trans1.trid
WHERE trans1.element_id = #myid#
AND trans2.source_language_code IS NULLs
#myid# is the ID of your current (possibly translated) post.
The algorithm works like this:
- Find out the translation ID (column
trid) for the current post by selecting the row for the given post ID (column
- Find all rows with the same translation ID
- Select only the row where the source language is
NULL – this is the original post.
You can use it like this:
$orig_lang_id = $wpdb->get_var("SELECT trans2.element_id FROM wp_icl_translations AS trans1 INNER JOIN wp_icl_translations AS trans2 ON trans2.trid = trans1.trid WHERE trans1.element_id = ".get_the_ID()." AND trans2.source_language_code IS NULL");
and then use
$orig_lang_id where required. Note that
NULL if the query fails. The main reason for the query to fail is if there is no entry for the given post ID in the
If the current post is the source post,
$orig_lang_id is the same as
get_the_ID(), i.e. the current ID of the post.
In my test, the code still works (i.e. returns the correct post ID) even when creating brand-new entry without any translations being present.
You are using linkchecker to check your WordPress site, but you get the following error multiple times:
$ linkchecker https://techoverflow.net
Parent URL https://techoverflow.net/, line 8, col 1
Real URL https://techoverflow.net/xmlrpc.php
Check time 1.394 seconds
Result Error: 405 Method Not Allowed
Installing a plugin that disables XMLRPC doesn’t help here – because the XMLRPC pingback link will still be present on every page.
Instead, just tell linkchecker to ignore the XMLRPC link altogether:
linkchecker https://techoverflow.net --ignore-url=/xmlrpc.php$
You are trying to run a docker container or do the docker tutorial, but you only get an error message like this:
docker: Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.26/containers/create: dial unix /var/run/docker.sock: connect: permission denied.
See 'docker run --help'.
The error message tells you that your current user can’t access the docker engine, because you’re lacking permissions to access the unix socket to communicate with the engine.
As a temporary solution, you can use
sudo to run the failed command as root.
However it is recommended to fix the issue by adding the current user to the
Run this command in your favourite shell and then completely log out of your account and log back in (if in doubt, reboot!):
sudo usermod -a -G docker $USER
After doing that, you should be able to run the command without any issues. Run
docker run hello-world as a normal user in order to check if it works. Reboot if the issue still persists.
Logging out and logging back in is required because the group change will not have an effect unless your session is closed.
You want to download a URL to a file using the requests python library, but you want to skip the download if it doesn’t exist
Use the following functions:
def download_file(filename, url):
Download an URL to a file
with open(filename, 'wb') as fout:
response = requests.get(url, stream=True)
# Write response data to file
for block in response.iter_content(4096):
def download_if_not_exists(filename, url):
Download a URL to a file if the file
does not exist already.
True if the file was downloaded,
False if it already existed
if not os.path.exists(filename):
You have a list of X/Y coordinates, for example:
coords = [(6.74219, -53.57835),
For these coordinates you want to compute the minimum bounding box.
You most likely found this post for one of two reasons:
- Either you haven’t heard of Z-Boxes and are interested in if they can somehow help you
- or you have to learn about Z-Boxes and you have absolutely no idea how to understand the mathematical definitions.
Either way, we’re going to investigate Z-Boxes – not using a box of formulas but using examples and Python code.
You have a ZIP file containing a single ESRI shapefile database (i.e. three files), for example the Natural Earth Countries database. Without unzipping the ZIP you want to use pyshp in order to read the data contain in the shapefile.
Occasionally I have to clean up some HTML code – mostly because parts of it were pasted into a CMS like WordPress from rich text editor like Word.
I’ve noticed that the formatting I want to remove is mostly based on
div elements with a
style attribute. Therefore, I’ve written a simple Python script based on BeautifulSoup4 which will replace certain tags with their contents if they have a
style attribute. While in some cases some other formatting might be destroyed by such a script, it is very useful for some recurring usecases.
Recently I’ve encountered a strange issue with the Broken Link Checker plugin for WordPress:
While all HTTP URLs work just fine, every single HTTPS URL yields an
Unknown error without any log message or explanation. Mehr lesen