show in espais associat the convos that belong to them

This commit is contained in:
jorge 2024-03-12 23:33:12 +01:00
parent b612a464f1
commit bebeb0afff
2 changed files with 31 additions and 54 deletions

View File

@ -90,16 +90,7 @@
</section>
<section class="xarxaprod-associat-convos">
<?php
// https://www.advancedcustomfields.com/resources/bidirectional-relationships/
// https://www.advancedcustomfields.com/resources/relationship/
;?>
<?php get_template_part( 'template-parts/section', 'last-convos' ); ?>
</section>
<section class="xarxaprod-associat-location">

View File

@ -18,47 +18,32 @@
//plugin is activated do
?>
<header>
<?php if ( get_post_type( ) == 'xarxaprod-associat' ){ ?>
<?php $slug_espai_associat =get_post_field( 'post_name', get_post() ) ; ?>
<?php
if( get_field('xxp_convo_espai_associat') ):
$espai_associat_posts = get_field('xxp_convo_espai_associat');
if( $espai_associat_posts ):
foreach( $espai_associat_posts as $post ):
setup_postdata($post);
//do somethin
the_title( '<h3> convos de'.'</h3>');
endforeach;
wp_reset_postdata();
endif;
endif;
?>
<?php //begin any query
// begin populate WP_Query with custom post type xarxaprod-associat
if ( get_post_type( ) == 'xarxaprod-associat' ){
$slug_espai_associat =get_post_field( 'post_name', get_post() ) ;
// https://developer.wordpress.org/reference/functions/get_posts/
// query ACF relationsihp
// https://wordpress.stackexchange.com/a/213375
$convos_query = new WP_Query(
array(
'post_type' => 'xarxaprod-convo',
'posts_per_page' => '3',
'meta_query' => array(
array(
'key' => 'xxp_convo_espai_associat', // name of the custom field
'value' => '"' . get_the_ID() . '"', // in ACF select Return format "Post ID"
'compare'=> 'LIKE', // matches exaclty "123", not just 123. This prevents a match for "1234"
)
)
)
);
?>
<h3> <a href="<?php echo home_url( '/convos/?xxp_convo_center=' ) . $slug_espai_associat ;?>"><?php echo esc_html__('Últimes convocatòries', 'xarxaprod'); ?> de <?php the_title(); ?></a></h3>
</header>
<main class="xarxaprod-last-convos xarxaprod-ultimes-convocatories">
<?php
// https://developer.wordpress.org/reference/functions/get_posts/
// https://www.advancedcustomfields.com/resources/true-false/
$convos_query = new WP_Query(
array(
'post_type' => array( 'xarxaprod-convo' ),
'posts_per_page' => '3',
//'meta_key' => 'xxp_convo_center',
'meta_key' => 'xxp_convo_espai_associat',
'meta_value' => $slug_espai_associat,
//'meta_query' => array (
// 'key' => 'xxp_convo_center',
// 'value' => $slug,
// 'compare' => '=',
//)
) );
?>
<?php } else { ?>
<h2> <a href="<?php echo site_url() . '/convocatories' ;?>"><?php echo esc_html__('Últimes convocatòries', 'xarxaprod'); ?></a></h2>
</header>
<main class="xarxaprod-last-convos xarxaprod-ultimes-convocatories">
<?php
<?php } //end populate WP_Query custom post type xarxaprod-associat
else { // begin populate WP_Query with others
// https://developer.wordpress.org/reference/functions/get_posts/
// https://www.advancedcustomfields.com/resources/true-false/
$convos_query = new WP_Query(
@ -66,12 +51,15 @@
'post_type' => array( 'xarxaprod-convo' ),
'posts_per_page' => '3'
) );
?>
<?php };?>
?>
<h2> <a href="<?php echo site_url() . '/convocatories' ;?>"><?php echo esc_html__('Últimes convocatòries', 'xarxaprod'); ?></a></h2>
</header>
<main class="xarxaprod-last-convos xarxaprod-ultimes-convocatories">
<?php }; //end populate WP_Query with others ?>
<?php //begin loop WP_Query ?>
<?php if ( $convos_query->have_posts() ) : ?>
<?php while ( $convos_query->have_posts() ) : $convos_query->the_post(); ?>
<div class="xarxaprod-card-each xarxaprod-convo-info-field">
<header class="entry-header">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" rel="bookmark" class="">
@ -110,10 +98,8 @@
<?php endwhile;//end of the loop ?>
<?php wp_reset_postdata(); ?>
<?php else : //if no post in query ?>
<p class="no-content"></p>
<?php endif; //end query ?>
<p class="no-content"> No convos </p>
<?php endif; //end WP_Query ?>
</main>
<?php } //closing if is_plugin_active ?>