trickery.net  

Go Back   trickery.net > Technical > Website Development

Reply
 
Thread Tools
Old 22-Aug-2017, 19:21   #1
dirky
quick panic, it's snowing
dirky's Avatar
Join Date: Oct 2003
Location: Italy
Posts: 2,713
dirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond repute
Wordpress - link to custom post

I'm sure this is pish but I'm missing something.

I'm extracting a post object using ACF and I'd like to link to the object itself, rather than the page that it's on.

Code:
<?php $post_objects = get_sub_field('items'); if( $post_objects ): ?>
 <div class="accordion-carousel">
  <?php foreach( $post_objects as $post): ?>
   <?php setup_postdata($post); ?>
   <img src="<?php the_field('theme_image') ?>">
  <?php endforeach; ?>
  <?php wp_reset_postdata(); ?>
 </div>
 <a>THIS NEEDS TO LINK TO /THEMES CUSTOM POST</a>
<?php endif; ?>
Anyone know?
dirky is offline  
Reply With Quote
Old 22-Aug-2017, 22:11   #2
Brocken
Bit lost
Brocken's Avatar
Join Date: Oct 2003
Posts: 5,935
Brocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond repute
the_permalink() within the loop links to the individual post
get_post_type_archive_link('post_type_here') links to the index/listings page of that CPT

What do you mean by link to the object itself?
Brocken is offline  
Reply With Quote
Old 23-Aug-2017, 19:43   #3
dirky
quick panic, it's snowing
dirky's Avatar
Join Date: Oct 2003
Location: Italy
Posts: 2,713
dirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond repute
Hmm, ok.

It's like, I have a 'products' custom post type and I want the user to be able to link to that custom post URL via an ACF field. I don't want to link to a post within that custom post, though I could do this then grab the archive link, but that's a bit shit to be honest as the user would be forced to select a specific post.

ACF lets you do all sorts but I can't see this kind of option.
dirky is offline  
Reply With Quote
Old 24-Aug-2017, 08:58   #4
Brocken
Bit lost
Brocken's Avatar
Join Date: Oct 2003
Posts: 5,935
Brocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond repute
use the_permalink() within the foreach loop and it'll link to that specific custom post.

Your problem is you're trying to link to the individual custom post outside of the loop
Brocken is offline  
Reply With Quote
Old 24-Aug-2017, 19:57   #5
dirky
quick panic, it's snowing
dirky's Avatar
Join Date: Oct 2003
Location: Italy
Posts: 2,713
dirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond repute
Oh man, I figured it would be straightforward.

Ok, next question: how can I let the user select a post then have the code link to the permalink of that post? So far ACF seems to 'force' you to select objects within that post. I could just use a page link but I'd like it to be slightly classier than that. I want the user to specify the post, then code ACF to get the title, permalink, etc.

Last edited by dirky; 24-Aug-2017 at 20:04.
dirky is offline  
Reply With Quote
Old 25-Aug-2017, 09:34   #6
Brocken
Bit lost
Brocken's Avatar
Join Date: Oct 2003
Posts: 5,935
Brocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond repute
ACF doesn't do anything to the posts it returns etc.

All the relationship + post object fields are doing is returning a post or posts. Then you loop through them in the same way you do regular posts.

And when you say user select a post what do you mean? Click a link to a post? Select it from a dropdown? Select it on a slider?
Brocken is offline  
Reply With Quote
Old 28-Aug-2017, 19:34   #7
dirky
quick panic, it's snowing
dirky's Avatar
Join Date: Oct 2003
Location: Italy
Posts: 2,713
dirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond repute
I want them to be able to select the post object, then the code will get the title, permalink etc. I just want to take away some of the legwork for the user. The alternative is they have to manually fill out title etc, so when the object changes, they'd need to update the advert.
dirky is offline  
Reply With Quote
Old 28-Aug-2017, 19:35   #8
dirky
quick panic, it's snowing
dirky's Avatar
Join Date: Oct 2003
Location: Italy
Posts: 2,713
dirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond repute
As mentioned, ACF let's you select a post object, but the front end end loops are built to get the posts and not the object itself. I hope that makes some kind of sense?
dirky is offline  
Reply With Quote
Old 28-Aug-2017, 21:46   #9
Brocken
Bit lost
Brocken's Avatar
Join Date: Oct 2003
Posts: 5,935
Brocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond reputeBrocken has a reputation beyond repute
I have no idea what you're trying to do. The loop is just a method of iterating through all the post objects. Wordpress sets the global $post to the current post object in the loop. All functions like the_title(), the_permalink() etc just use that global $post object to return the correct title/permalink.

In the case of the title it's just accessing $post->post_title and running it through some filters and then returning it.
Brocken is offline  
Reply With Quote
Old 03-Sep-2017, 21:21   #10
dirky
quick panic, it's snowing
dirky's Avatar
Join Date: Oct 2003
Location: Italy
Posts: 2,713
dirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond repute
Hey Brocken,

Any idea why a posts loop (to get other posts excluding current post) on single.php would only be producing 1/3 results? And the first result at that? Indeed, how would one exclude the current post?

Cheers man.
dirky is offline  
Reply With Quote
Old 03-Sep-2017, 21:22   #11
dirky
quick panic, it's snowing
dirky's Avatar
Join Date: Oct 2003
Location: Italy
Posts: 2,713
dirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond repute
Ahh, I've just twigged it's restricting to the category of the post that it's on
dirky is offline  
Reply With Quote
Old 03-Sep-2017, 21:31   #12
dirky
quick panic, it's snowing
dirky's Avatar
Join Date: Oct 2003
Location: Italy
Posts: 2,713
dirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond reputedirky has a reputation beyond repute
Tis ok, I figured it out
dirky is offline  
Reply With Quote
Reply

Go Back   trickery.net > Technical > Website Development


Similar Threads
Thread Thread Starter Forum Replies Last Post
link to forum homepage Heartwork Feedback & Forum Requests 0 26-Nov-2004 09:37
Custom Sprays mope Half-Life: Counter-Strike: Rats 20 27-Jul-2004 14:51
Halo Custom Edition (PC) The Dark One News 1 07-May-2004 12:59
The Compulsory Xmas Post JinxM Quake & Doom Series 4 01-Jan-2004 16:41
Custom Forum!! :P wooly-back-jack Feedback & Forum Requests 9 22-Nov-2003 18:10

Users Viewing Thread: 1 (0 members and 1 guests)
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 07:39.


Powered by vBulletin® Version 3.7.0 Release Candidate 3
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
Copyright 2003 - 2013, trickery.net