I would like to create a relationship between 2 Custom Post Type avoiding that the user has to go to both to create the link.
In absolute terms, I would like the user to go to only one Custom Post Type (writing) which remains fairly basic: A title field, a text field, an image field, a link field for documents or url, and finally a selector field to select its parent (created with ACF).
In the hierarchy of the site, these posts created are at the end of the race, therefore, are only post children. They will display with "single.php".
The site obviously contains different menus which also have different sub-menus, a front-page.php for the home page, for the main menus we have the archive pages and for the sub-menus of the single pages.
The other Custom Post Types are the site menus which each contain their respective submenus. The user doesn't have to go here, hence I would like to create a parent/child relationship only by going into the child Custom Post Type.
For example, in my home page (front-page.php), I have a "Company" part if I click on it, I arrive on "archive.creb.php" where there is "Office", Secretariat" and "Management", if I click on "Office" I arrive on "single.creb.php", in this part, there is "the team" and "the calendar", if I click on "the team", I arrive at "single.php".
The team page (just like the "calendar" page) is an article written by the user.
So I'm looking for a way so that, when the user creates an article, he can choose where it will be (with the ACF selector field), and therefore choose its parent AND in addition, that the link of the article appears in this parent.
I know how to do this kind of operation by configuring a relational field in the 2 Custom Post Types concerned with ACF, but not with just one.
I did some research, especially on the ACF doc and I found this:
https://www.advancedcustomfields.com/resources/relationship/
https://www.advancedcustomfields.com/resources/querying-relationship-fields/
So I tried to adapt the ACF example with my code, but it's not easy because it's not quite the same... By schematizing the ACF example to mine, it gives this:
In both cases there is indeed a selection field creation, except that in the ACF example its selector chooses the child and I choose the parent. So I tried to reverse, using the code from single.location.php in my single.creb.php.... But it doesn't work.. my single.creb.php page shows a link loop to himself
So... I hope I was clear in my question! Hoping for an answer
Here are some codes :
functions.php
function custom_post_type(){
$arg = [
'public'=> true,
'label'=> 'CREB',
'show_in_rest' => true,
'supports'=>array('title', 'thumbnail', 'excerpt'),
'has_archive'=>true,
'menu_icon'=> 'dashicons-groups'
];
register_post_type('creb', $arg);
$arg = [
'public'=> true,
'label'=> 'redaction',
'show_in_rest' => true,
'supports'=>array('title', 'thumbnail', 'excerpt'),
'has_archive'=>true,
'menu_icon'=> 'dashicons-book-alt'
];
register_post_type('redaction', $arg);
}
add_action('init', 'custom_post_type');
single-creb.php
<?php get_header(); ?>
<!-- single creb -->
<main id="" class="">
<div class="">
<h1 class="">single CREB</h1>
<?php
if(have_posts()){
while(have_posts()){
the_post();
the_title();
$redac = get_field('textesousmenu');
if($redac){
echo $redac;
};
};
};
?>
</div>
</main>
<?php get_footer(); ?>
single.php
<?php get_header(); ?>
<!-- single creb -->
<main id="" class="">
<div class="">
<h1 class="">single</h1>
<?php
if(have_posts()){
while(have_posts()){
the_post();
the_title();
$redac = get_field('texte');
if($redac){
echo $redac;
};
$img = get_field('img');
if($img){
echo wp_get_attachment_image($img, 'modale');
}
if (have_rows('liendocurl')){?>
<ul class="">
<?php while (have_rows('liendocurl')){
the_row();
$nom = get_sub_field('nomlien');
$docurl = get_sub_field('urllien');?>
<li>
<a href="<?php echo $docurl; ?>" target="_blank">
<?php echo $nom ?>
</a>
</li>
<?php } ?>
</ul>
<?php }
$lien = get_field('relation');
if($lien){?>
<ul>
<?php
$name = get_the_title($lien->ID);
$link = get_permalink($lien->ID);
?>
<li>
<a href="<?php echo $link;?>">
<?php echo $name; ?>
</a>
</li>
</ul><?php
}
};
};
?>
</div>
</main>
<?php get_footer(); ?>
thank you in advance
I suppose this is something simple, but couldn't find a solution anywhere.
Currently, my website shows <h1>"Products"</h1> title on shop archive page, but on single product pages as well. Is it possible to change default title on single product pages to product name?
Here is my website. As you can see, above breadcrumbs, there is a default shop title. And there I want to display, product name instead.
<section class="<?php echo esc_attr($class_name) ?>" <?php echo wp_kses_post($bg_style); ?>>
<div class="page-title-inner">
<div class="container"><h1><?php echo esc_html($page_title); ?></h1> <?php great_store_the_breadcrumb(); ?>
</div>
</div>
</section>
I have a link with me. This is the link:
http://localhost/rajab/product-category/pvc-hose/
I have made a a category "PVC Hose" having slug name "pvc-hose" and displayed on a page. when i am clicking this category, it goes to a link as shown above.i wanted to display all the posts in this category on linked page. Can anyone say how to display it there.
Simply create a taxonomy.php file in your root folder with the following code
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
// Your markup and template tags like
the_title();
echo '</br>';
}
}
<li class="cbp-item houses cbp-l-grid-masonry-height1">
<a class="cbp-caption cbp-lightbox" data-title="PVC Air Hose" href="<?php bloginfo('template_url'); ?>/images/buiding/pvc/img1.jpg">
<div class="cbp-caption-defaultWrap">
<img src="<?php bloginfo('template_url'); ?>/images/buiding/pvc/img1.jpg" alt="">
</div>
</a>
<h4><?php $data->post_title; ?></h4>
</li>
i wanted to repeat this code in the taxonomy file..I wanted to display not only the title and content but also featured image.
I need wordpress plugin for this kind of header image http://www.slb.com/services/drilling.aspx like in this web site. And this image will not be slider but it's static image on perticular page and category and also different image for all categories and pages.
Easiest & best way is create a custom field named banner & in your header.php place below code.
<div class="banner">
<?php if(get_post_meta($post->ID, 'banner', true)) : ?>
<img src="<?php echo get_post_meta($post->ID, 'banner', true); ?>" />
<?php endif; ?>
<div>
But as you want plugin to do this, have a look at plugin named Dynamic Header.
Currently during the sidebar registration we can mention "before_widget" and "after_widget". But this limit the extent we can wrap the widgets.
Is there a way I can display the widgets in any manner I want to, within a sidebar
e.g
<?php foreach($widgets as $widget): ?>
<div>
<h1>heading</h1>
<p>details</p>
<?=widget->show()?>
</div>
<?php endforeach; ?>
Thanks.