Site logo

[Support request] Custom field in Archive element

Home Forums Support [Support request] Custom field in Archive element

Home Forums Support Custom field in Archive element

Viewing 15 posts - 1 through 15 (of 33 total)
  • Author
    Posts
  • #1938251
    Dan

    Hi,
    I have a custom post type which has some custom fields in it. One of them is called ‘Short description’.
    In the archive page which displays the list of post in that CPT category I would like to display under the post the ‘short description’ which is a custom field.
    currently, it is not displaying.
    You can see the setting in the screenshot:
    https://www.dropbox.com/s/wx0rrsz961n2ybx/post_meta.jpg?dl=0

    And the output:
    https://www.dropbox.com/s/b8cdil8l0mhtv7m/output.jpg?dl=0

    Also, I would like to make all archive pages (categories and tags) of this custom post type display in 3 columns. can that be done via the block elements, or will it need some custom CSS?

    Thanks!
    Dan

    #1938282
    Ying
    Staff
    Customer Support

    Hi Dan,

    Just to confirm is the Custom filed called short description or short_description?

    Please make sure the names you entered are the same.

    And to add column to your custom post type archive, please check this guide:
    https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-columns-to-your-custom-post-type

    Let me know if you need further assistance 🙂

    #1938288
    Dan

    Hi Ying,
    Thanks for replying.
    the custom field is short_description

    Regarding the columns, I added this snippet

    add_filter( 'generate_blog_columns','tu_portfolio_columns' );
    function tu_portfolio_columns( $columns ) {
        if ( is_post_type_archive( 'catalog' ) ) {
            return 33;
        }
    
        return $columns;
    }

    But it’s still 1 column

    Dan

    #1938293
    Dan

    just mentioning that the archive page is built with block elements.
    See screenshot:
    https://www.dropbox.com/s/1bz43p3ig99xv6s/content-grid.jpg?dl=0

    Dan

    #1938300
    Ying
    Staff
    Customer Support

    Does your blog has 3 columns set already? If so, you only need this PHP snippet:
    https://docs.generatepress.com/article/using-columns-in-the-blog/#adding-columns-to-your-custom-post-type

    If your blog has different columns number, then you’ll need this PHP snippet as well:
    https://docs.generatepress.com/article/using-columns-in-the-blog/#changing-the-number-of-columns

    For the custom filed, your settings in the element looks right, just wondering what’s the content highlighted in red?
    https://www.screencast.com/t/AAVJ7lXk4R

    Let me know.

    #1938301
    Dan

    I think I’ll figure out the columns with custom CSS, thanks.
    The content in red it the post’s title.

    #1938304
    Dan

    in the post itself, this is the ‘short_description’ custom field.
    (it’s part of an ACF block):
    https://www.dropbox.com/s/gqvmoucivm047y0/short-description.jpg?dl=0

    Dan

    #1938311
    Ying
    Staff
    Customer Support

    Not sure why it doesn’t work by looking at the screenshots.

    Can you provide access to admin so we can have look at the back end?

    #1938322
    Dan

    The custom field is from an ACF within a block, could that influence the output?
    The site is still in local dev, I’ll upload to staging in a few days.

    Another related question, I would like to make the main category (archive) page a static one, so I tried with elements but the output isn’t right, it still creates some sort of loop (when using the ‘content template’ element type).
    Would it be correct to create a ‘page header’ element, set the location to the custom post type archive, create the blocks I want to see and then hide the loop with CSS?

    #1938354
    Ying
    Staff
    Customer Support

    The site is still in local dev, I’ll upload to staging in a few days.

    We can have a look then, let us know.

    Would it be correct to create a ‘page header’ element, set the location to the custom post type archive, create the blocks I want to see and then hide the loop with CSS?

    Doesn’t sound right, in this way, all the content is still loading, not great for your site performance.

    Give this PHP snippet a try:
    https://docs.wpshowposts.com/article/use-static-pages-as-category-archives/

    Let’s say the category is called ‘event’ , you need to create a new static page named ‘event’, put everything you want to show in this static page.

    Then set the Category base to . at settings > permalinks.

    With the PHP snippet, the default category archive page will be replaced by the static page.

    #1938365
    Dan

    Thanks, Yes, I thought there may be a better way.
    But I would like the static page be for the main archive of the CPT not for specific categories.
    Is it possible to check if it’s the archive of the CPT and then replace it with the static page (without causing issues for other categories and the default WP posts and categories)

    #1938383
    Ying
    Staff
    Customer Support

    In this case, you can try something like this:

    function archive_to_custom_archive() {
        if( is_post_type_archive( 'event' ) ) {
            wp_redirect( home_url( '/events/' ), 301 );
            exit();
        }
    }
    add_action( 'template_redirect', 'archive_to_custom_archive' );
    #1938384
    Dan

    ok, so that would be a simple redirect to the static page?

    #1938401
    Ying
    Staff
    Customer Support

    Yes.

    #1938402
    Dan

    ok, thanks

Viewing 15 posts - 1 through 15 (of 33 total)
  • You must be logged in to reply to this topic.