Mu-Plugin 1.5.0: Reihenfolge-Feld und Loop-Grid-Sortierung
This commit is contained in:
@@ -443,6 +443,7 @@ const meta = {
|
||||
faq_ueberschrift: a.faq_ueberschrift || '',
|
||||
cta_ziel: a.cta_ziel || '',
|
||||
stand_datum: a.stand_datum || heute,
|
||||
ratgeber_reihenfolge: Number.isFinite(Number(a.reihenfolge)) && a.reihenfolge !== null && a.reihenfolge !== '' ? Number(a.reihenfolge) : 999,
|
||||
faq: Array.isArray(a.faq)
|
||||
? a.faq.filter(f => f && f.frage).map(f => ({ frage: String(f.frage), antwort: String(f.antwort || '') }))
|
||||
: [],
|
||||
|
||||
22
build/reihenfolge_setzen.py
Normal file
22
build/reihenfolge_setzen.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Schreibt ratgeber_reihenfolge aus artikel/*.json in die bestehenden WP-Beitraege (braucht Mu-Plugin ab 1.5.0)."""
|
||||
import base64, glob, json, urllib.request
|
||||
E = {}
|
||||
for z in open('.env', encoding='utf-8'):
|
||||
z = z.strip()
|
||||
if z and not z.startswith('#') and '=' in z:
|
||||
k, v = z.split('=', 1); E[k] = v.strip().strip('"')
|
||||
AUTH = 'Basic ' + base64.b64encode(f"{E['WP_USER']}:{E['WP_APP_PASSWORD']}".encode()).decode()
|
||||
WP = E['WP_BASE_URL'].rstrip('/') + '/wp-json/wp/v2/posts'
|
||||
def ruf(url, daten=None):
|
||||
r = urllib.request.Request(url, data=json.dumps(daten).encode() if daten else None, method='POST' if daten else 'GET',
|
||||
headers={'Authorization': AUTH, 'Content-Type': 'application/json'})
|
||||
return json.load(urllib.request.urlopen(r, timeout=60))
|
||||
for f in sorted(glob.glob('artikel/artikel-*.json')):
|
||||
a = json.load(open(f, encoding='utf-8'))
|
||||
treffer = ruf(f"{WP}?slug={a['slug']}&status=draft,publish,pending,future,private&context=edit&_fields=id,meta")
|
||||
if not treffer:
|
||||
print('kein Beitrag', a['slug']); continue
|
||||
pid = treffer[0]['id']
|
||||
neu = ruf(f"{WP}/{pid}?_fields=id,meta", {'meta': {'ratgeber_reihenfolge': a.get('reihenfolge', 999)}})
|
||||
print(pid, a['slug'], neu['meta'].get('ratgeber_reihenfolge', 'Feld unbekannt, Plugin 1.5.0 fehlt'))
|
||||
Reference in New Issue
Block a user