Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9127479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:17:30+00:00 2026-06-17T07:17:30+00:00

I have a meta box on a custom post type for width. Im trying

  • 0

I have a meta box on a custom post type for width. Im trying to use get_post_meta to place some CSS in the head. Everything is working but the meta value is not passing through. Here is my function:

function mo_carousel_css(){
    global $post;
    $width = get_post_meta( $post->ID, 'mo_carousel_width', true );
    ?>
    <style type="text/css">
        .jcarousel-container-horizontal{
        width:<?php echo $width; ?>px;
        }
    </style>
    <?php
    }

I have checked the database and the meta key/value is being stored properly as mo_carousel_width and 500 respectively. I thought global $post; would be the fix but no luck.

The value is retrieved fine in the metabox in the backend by accessing $object but that doesn’t seem to work either. This is code for the form that is creating the value:

    /* Display the post meta box. */
function mo_carousel_meta_box( $object, $box ) { ?>

    <?php wp_nonce_field( basename( __FILE__ ), 'mo_carousel_nonce' ); ?>
    <p>
        <span>Carousel Size</span>
        </br>
        <input type="text" name="mo-carousel-width" id="mo-carousel-width" value="<?php echo esc_attr( get_post_meta( $object->ID, 'mo_carousel_width', true ) ); ?>" size="10" />
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:17:31+00:00Added an answer on June 17, 2026 at 7:17 am

    I wrote this by studying the Shortcode API, and I think it should work but I haven’t tried it.

    function mo_carousel_css() {
        global $post;
        preg_match( '/' . get_shortcode_regex() . '/s', $post->post_content, $m); 
        if (is_array($m) && $m[2] == 'shortcode' ) { 
                    $shortcode_args = shortcode_parse_atts( $m[3] );
            $width = get_post_meta( $shortcode_args['idatt'], 'mo_carousel_width', true );
            <style type="text/css">
                .jcarousel-container-horizontal{ width:<?php echo $width; ?>px; }
            </style>
        } 
    }
    

    Basically what it does is check if the shortcode is being used in the current post. If the shortcode is being used, retrieve the attributes from it and use the id attribute to get post meta data.

    If your shortcode is [displayCustomPost id=24] then you would have to replace shortcode with displayCustomPost and idatt with id.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: html: <html> <head> <link rel=stylesheet type=text/css href=StyleSheet.css> <meta http-equiv=content-type
So I have a custom meta box which I'm trying to pull dynamic content
I have created a custom post type 'hotel' and custom 'taxonomy' so when administrator
I have a declared a custom post type in function.php like this : register_post_type('movies',
Been trying to add custom post type which was successful the problem i am
Hey guys, I have a custom post type, portfolio, and I want to store
I have been trying to display this meta box info in my template as
I have successfully pulled a custom post type through into a drop-down that is
I have a custom meta box(taxonomy) that is positioned on side of my custom
I have been messing around with my meta descriptions, trying to make them more

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.