GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - CodeAtCode/wp-cli-getbyurl: Get id by URL in WordPress for post types, taxonomies and media

This repository was archived by the owner on Feb 27, 2024. It is now read-only.
BranchesTags
Open more actions menu

Latest commit

 

History

20 Commits
20 Commits

Folders and files

NameName
Last commit message
Last commit date
LICENSE
LICENSE
 
 
command.php
command.php
 
 
composer.json
composer.json
 
 
readme.md
readme.md
 
 

Repository files navigation

How to use it

License

Warning

There is an official parameter for this in WP-CLI: https://developer.wordpress.org/cli/commands/post/url-to-id/

This package will be not updated!

Install

wp package install codeatcode/wp-cli-getbyurl

Output structure

Kind of content | post id | post type/taxonomy

Commands

To get the id and post type by url:

wp get-by-url --skip-plugins --skip-themes http://demo.test/2018/10/your-post

Output:

post | 33 | post

To get the id and taxonomy by url:

wp get-by-url --skip-plugins --skip-themes http://demo.test/tag/test/

Output:

term | 2 | post_tag

Works also with attachment.

Why skip plugins and themes

It is a good practice in WP CLI when you have to execute commands that are heavy of resources to not load plugins and themes for a lot of reasons.

Why the separator is pipe?

In that way is more easy to do script on it in bash or other languages

How to use it


# How to use the script:
#     cat list.txt | xargs -n1 remove-page-by-url.sh

out=$(wp get-by-url "$1" --skip-plugins --skip-themes)
if [[ -n $out ]]; then
    command=$(cut -d'|' -f1 <<< "$out" | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')
    id=$(cut -d'|' -f2 <<< "$out" | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')
    what=$(cut -d'|' -f3 <<< "$out" | sed 's/^[[:blank:]]*//;s/[[:blank:]]*$//')
    if [[ "$what" == 'post' || "$what" == 'attachment' ]]; then
        wp "$command" delete "$id" --skip-plugins --skip-themes
    else
        wp "$command" delete "$what" "$id" --skip-plugins --skip-themes
    fi
fi

About

Get id by URL in WordPress for post types, taxonomies and media

Topics

wordpresswp-cliwp-cli-commandwp-cli-package

Resources

Readme
GPL-2.0 license
Activity
Custom properties

Stars

5 stars

Watchers

2 watching

Forks

0 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.