Marcus
Avatar Marcus
Themenersteller
Guru (224 Beiträge)

ACF-Checkbox-Feld ausgeben

am 27.11.2022, 18:27 Uhr eröffnete Marcus folgenden Thread
Wordpress    0 Antwort(en).

Mit ACF gebe ich zwei Auswahlfelder aus mit folgendem Code:

add_filter( 'the_content', 'mmx_maybe_add_copyright_to_content', 500);
function mmx_maybe_add_copyright_to_content( $content ) {

$copyright = array();

/* thumbnail copyright */
$thumbnail_id = get_post_thumbnail_id();
$thumbnail_meta = array();
$thumbnail_meta[] = get_post_meta( $thumbnail_id, 'name', true ) ?? NULL;
$thumbnail_meta[] = get_post_meta( $thumbnail_id, 'organisation', true ) ?? NULL;

if( count( array_filter ( $thumbnail_meta ) ) >= 1 ){
$thumbnail_copyright = implode( ', ', $thumbnail_meta );
$copyright[] = '

© ' . $thumbnail_copyright . '

';
}

/* in content images copyright */

preg_match( '|<img.*?src=".*?/?>|', $content, $matches );
foreach( $matches as $img ){
preg_match( '|(src=")(.*?)"|', $img, $url);
$attachment_id = attachment_url_to_postid( $url[2] );
$attachment_meta = array();
$attachment_meta[] = get_post_meta( $attachment_id, 'name', true ) ?? NULL;
$attachment_meta[] = get_post_meta( $attachment_id, 'organisation', true ) ?? NULL;
if( count( array_filter ($attachment_meta) ) >= 1 ){
$attachment_copyright = implode( ', ', $attachment_meta );
$copyright[] = '

© ' . $attachment_copyright . '

';
}
}

$images_found = count( array_filter ( $copyright ) );
if( $images_found >= 1 ){
$copyright_list = '


';
$content .= $copyright_list;
}


return $content;
}

Jetzt möchte ich entsprechend dem angezeigten Code für die Auswahlfelder auch einen Text ausgeben, wenn eine Checkbox angeklickt wird.

Das versuche ich mit dem folgenden Code, den ich vor

/* in content images copyright */

einfüge

/* thumbnail copyright obs */
$thumbnail_id_obs = get_post_thumbnail_id();
$thumbnail_meta_obs = array();
$thumbnail_meta_obs[] = get_post_meta( $thumbnail_id_obs, 'artikelfoto', true ) ?? NULL;

if( count( array_filter ( $thumbnail_meta_obs ) ) >= 0 ){
$thumbnail_copyright_obs = implode( ', ', $thumbnail_meta_obs );
$copyright[] = '

© ' . $thumbnail_copyright_obs . '

';
}

Leider klappt das nicht wie gewünscht.

var_dump($thumbnail_copyright_obs); ergibt

string(5) "Array"


Das Regional-Magazin für Lüneburg und die Region:
salzsau-panorama.de



    « zurück zu: Wordpress

    Das Seitenreport Forum hat aktuell 5273 Themen und 36107 Beiträge.
    Insgesamt sind 48345 Mitglieder registriert.