Forum Replies Created

Viewing 15 replies - 76 through 90 (of 274 total)
  • Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    After doing more research i might be able to articulate this question better.

    How can i get a custom post type to output its content and meta data without creating a theme template so the user can still switch themes if they wish?

    Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    This seemed to do the trick: “get_post_meta( $post->ID”

    <?php
    
        $connected = new WP_Query( array(
        'connected_type' => 'recipes_to_ingredients',
        'connected_items' => get_queried_object(),
    
    ) );
    
    while( $connected->have_posts() ) : $connected->the_post();
    
        $cost = get_post_meta( $post->ID, 'foxware-ingredient-cost', true );
    
            echo '<li>';
    
            the_title();
    
            // Display cost
            echo '<br>';
             echo 'Cost: ' . $cost;
            echo '</li>';
    endwhile;

    Hi,

    Did this end up working?

    I am trying to query a custom meta field value from a connected post type.

    I have recipes and ingredients CPTs with a p2p connection type recipes_to_ingredients. I can successfully query and list all connected ingredients, but i can’t figure out how to simply display a meta key/value as well.

    Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    thanks for confirming that ??

    Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    change this line `<?php
    $args = array( ‘post_type’ => ‘foxware_recipe’ );

    ?>`

    to

    <?php
    $args = array( 'post_type' => array( 'foxware_recipe' ), 'posts_per_page' => '1' );
    ...
    ?>

    seemed to do the trick. Although not sure if that is the correct standard.

    Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    I think i found a solution to this by using post-to-post plugin

    Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    Thanks

    Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    I discovered it was a problem specifically related to WC Subscriptions and didnt affect non subscription orders.

    Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    oh ok cool thanks.

    Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    In the end i discovered this is most likely an issue with my theme Flatsome, When i use a different page template the white space disappears.

    Thanks for your response, ill contact the theme devs.

    Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    Oh awesome thanks a lot for that, didn’t even know about these. this is pretty cool ?? – looking forward to updates to the Custom Content Types module.

    Thanks for your help Jeremy.

    Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    Thanks for clearing that up for me.

    Restaurant menus, wow that’s a good idea. But i’m way more excited about Comics post types, Gonna have to start a new blog when that one is released.

    Thanks ??

    Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    Thanks Jess and MacManX and sdayman, you all helped ?? i appreciate it alot.

    I think its starting to work better.

    thanks ??

    BruteProtect seems like a really cool thing, i wonder why no one did it before. no wonder automatiic picked it up, also havent seen automatiic do that before, thats pretty cool!

    it reminds me of Askimet, thats probably why they want you ?? anyway congrats.

    Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    I had a child theme going, i deactivated that and cleared my cache and that seemed to have fixed it.

    I’ll have to comb through my child theme and find the error, i forget where i edited it last, but at least it was easy to switch over.

    Thanks for your help Mandie

    Thread Starter Julian Fox (greataussiepie)

    (@greataussiepie)

    Finally managed to do it ?? i was browsing many tutorials online but finally when i just copied and pasted the code directly from the codex and then just copied the add_action instead of the whole function it worked better, but it only seemed to work when i used the code from the codex.

    I think this is resolved but if anyone can help me improve what im trying to do that would be awesome. I now have to add meta boxs to the custom post types and then create a relationship between recipes and ingredients. I want to list the ingredients on the add new or edit recipe page. I think i mentioned that i decided to use a custom post type relationship instead of taxonomy because i want to add lots more data to ingredient post type later on so i can perform calculations.

    My code now looks like this:

    add_action( 'init', 'create_foxware_recipe_post_types' );
    /**
     * Register a post type.
     *
     * @link https://codex.www.ads-software.com/Function_Reference/register_post_type
     */
    function create_foxware_recipe_post_types() {
    	$labels = array(
    		'name'               => _x( 'Recipes', 'post type general name', 'your-plugin-textdomain' ),
    		'singular_name'      => _x( 'Recipe', 'post type singular name', 'your-plugin-textdomain' ),
    		'menu_name'          => _x( 'Recipes', 'admin menu', 'your-plugin-textdomain' ),
    		'name_admin_bar'     => _x( 'Recipe', 'add new on admin bar', 'your-plugin-textdomain' ),
    		'add_new'            => _x( 'Add New', 'Recipe', 'your-plugin-textdomain' ),
    		'add_new_item'       => __( 'Add New Recipe', 'your-plugin-textdomain' ),
    		'new_item'           => __( 'New Recipe', 'your-plugin-textdomain' ),
    		'edit_item'          => __( 'Edit Recipe', 'your-plugin-textdomain' ),
    		'view_item'          => __( 'View Recipe', 'your-plugin-textdomain' ),
    		'all_items'          => __( 'All Recipes', 'your-plugin-textdomain' ),
    		'search_items'       => __( 'Search Recipes', 'your-plugin-textdomain' ),
    		'parent_item_colon'  => __( 'Parent Recipes:', 'your-plugin-textdomain' ),
    		'not_found'          => __( 'No Recipes found.', 'your-plugin-textdomain' ),
    		'not_found_in_trash' => __( 'No Recipes found in Trash.', 'your-plugin-textdomain' )
    	);
    
    	$args = array(
    		'labels'             => $labels,
    		'public'             => true,
    		'publicly_queryable' => true,
    		'show_ui'            => true,
    		'show_in_menu'       => true,
    		'query_var'          => true,
    		'rewrite'            => array( 'slug' => 'recipe' ),
    		'capability_type'    => 'post',
    		'has_archive'        => true,
    		'hierarchical'       => true,
    		'menu_position'      => 5,
    		'menu_icon' => plugins_url( 'images/foxware_icon.png', __FILE__ ),
    		'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt' )
    	);
    
    	register_post_type( 'foxware_recipe', $args );
    
    	$labels = array(
    		'name'               => _x( 'Ingredients', 'post type general name', 'your-plugin-textdomain' ),
    		'singular_name'      => _x( 'Ingredient', 'post type singular name', 'your-plugin-textdomain' ),
    		'menu_name'          => _x( 'Ingredients', 'admin menu', 'your-plugin-textdomain' ),
    		'name_admin_bar'     => _x( 'Ingredient', 'add new on admin bar', 'your-plugin-textdomain' ),
    		'add_new'            => _x( 'Add New', 'Ingredient', 'your-plugin-textdomain' ),
    		'add_new_item'       => __( 'Add New Ingredient', 'your-plugin-textdomain' ),
    		'new_item'           => __( 'New Ingredient', 'your-plugin-textdomain' ),
    		'edit_item'          => __( 'Edit Ingredient', 'your-plugin-textdomain' ),
    		'view_item'          => __( 'View Ingredient', 'your-plugin-textdomain' ),
    		'all_items'          => __( 'All Ingredients', 'your-plugin-textdomain' ),
    		'search_items'       => __( 'Search Ingredients', 'your-plugin-textdomain' ),
    		'parent_item_colon'  => __( 'Parent Ingredients:', 'your-plugin-textdomain' ),
    		'not_found'          => __( 'No Ingredients found.', 'your-plugin-textdomain' ),
    		'not_found_in_trash' => __( 'No Ingredients found in Trash.', 'your-plugin-textdomain' )
    	);
    
    	$args = array(
    		'labels'             => $labels,
    		'public'             => true,
    		'publicly_queryable' => true,
    		'show_ui'            => true,
    		'show_in_menu'       => true,
    		'query_var'          => true,
    		'rewrite'            => array( 'slug' => 'ingredient' ),
    		'capability_type'    => 'post',
    		'has_archive'        => true,
    		'hierarchical'       => true,
    		'menu_position'      => 5,
    		'menu_icon' => plugins_url( 'images/foxware_icon.png', __FILE__ ),
    		'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt' )
    	);
    
    	register_post_type( 'foxware_ingredient', $args );
    
    		$labels = array(
    		'name'               => _x( 'Suppliers', 'post type general name', 'your-plugin-textdomain' ),
    		'singular_name'      => _x( 'Supplier', 'post type singular name', 'your-plugin-textdomain' ),
    		'menu_name'          => _x( 'Suppliers', 'admin menu', 'your-plugin-textdomain' ),
    		'name_admin_bar'     => _x( 'Supplier', 'add new on admin bar', 'your-plugin-textdomain' ),
    		'add_new'            => _x( 'Add New', 'Supplier', 'your-plugin-textdomain' ),
    		'add_new_item'       => __( 'Add New Supplier', 'your-plugin-textdomain' ),
    		'new_item'           => __( 'New Supplier', 'your-plugin-textdomain' ),
    		'edit_item'          => __( 'Edit Supplier', 'your-plugin-textdomain' ),
    		'view_item'          => __( 'View Supplier', 'your-plugin-textdomain' ),
    		'all_items'          => __( 'All Suppliers', 'your-plugin-textdomain' ),
    		'search_items'       => __( 'Search Suppliers', 'your-plugin-textdomain' ),
    		'parent_item_colon'  => __( 'Parent Suppliers:', 'your-plugin-textdomain' ),
    		'not_found'          => __( 'No Suppliers found.', 'your-plugin-textdomain' ),
    		'not_found_in_trash' => __( 'No Suppliers found in Trash.', 'your-plugin-textdomain' )
    	);
    
    	$args = array(
    		'labels'             => $labels,
    		'public'             => true,
    		'publicly_queryable' => true,
    		'show_ui'            => true,
    		'show_in_menu'       => true,
    		'query_var'          => true,
    		'rewrite'            => array( 'slug' => 'supplier' ),
    		'capability_type'    => 'post',
    		'has_archive'        => true,
    		'hierarchical'       => true,
    		'menu_position'      => 5,
    		'menu_icon' => plugins_url( 'images/foxware_icon.png', __FILE__ ),
    		'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt' )
    	);
    
    	register_post_type( 'foxware_supplier', $args );
    
    }
Viewing 15 replies - 76 through 90 (of 274 total)